Skip to content

Commit 08cdd2e

Browse files
committed
sanity: make NodePublishVolume more generic
The input validation tests for the `NodePublishVolume` RPC (and others) depends on the ordering by which a CSI node plugin performs the validation checks. This was hidden because all checks tested for return the same error. However, when adding a test which expects a different error code, this becomes an issue. Instead of constructing 'mostly-invalid' requests in many of the tests, this patch changes the strategy to construct a *valid* request by default, then in every test only switch the field under test to some invalid value, then asserting the expected error code is returned.
1 parent 155cf95 commit 08cdd2e

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

pkg/sanity/node.go

+35-35
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,34 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
346346
})
347347

348348
Describe("NodePublishVolume", func() {
349+
var req *csi.NodePublishVolumeRequest
350+
351+
BeforeEach(func() {
352+
stagingTargetPath := ""
353+
if nodeStageSupported {
354+
stagingTargetPath = sc.StagingPath
355+
}
356+
357+
req = &csi.NodePublishVolumeRequest{
358+
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
359+
StagingTargetPath: stagingTargetPath,
360+
TargetPath: sc.TargetPath + "/target",
361+
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
362+
Readonly: false,
363+
Secrets: sc.Secrets.NodePublishVolumeSecret,
364+
}
365+
})
366+
367+
JustAfterEach(func() {
368+
if CurrentGinkgoTestDescription().Failed {
369+
fmt.Fprintf(GinkgoWriter, "Request was %v\n", req)
370+
}
371+
})
372+
349373
It("should fail when no volume id is provided", func() {
350-
_, err := c.NodePublishVolume(
351-
context.Background(),
352-
&csi.NodePublishVolumeRequest{
353-
Secrets: sc.Secrets.NodePublishVolumeSecret,
354-
},
355-
)
374+
req.VolumeId = ""
375+
376+
_, err := c.NodePublishVolume(context.Background(), req)
356377
Expect(err).To(HaveOccurred())
357378

358379
serverError, ok := status.FromError(err)
@@ -361,13 +382,9 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
361382
})
362383

363384
It("should fail when no target path is provided", func() {
364-
_, err := c.NodePublishVolume(
365-
context.Background(),
366-
&csi.NodePublishVolumeRequest{
367-
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
368-
Secrets: sc.Secrets.NodePublishVolumeSecret,
369-
},
370-
)
385+
req.TargetPath = ""
386+
387+
_, err := c.NodePublishVolume(context.Background(), req)
371388
Expect(err).To(HaveOccurred())
372389

373390
serverError, ok := status.FromError(err)
@@ -376,15 +393,9 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
376393
})
377394

378395
It("should fail when no volume capability is provided", func() {
379-
_, err := c.NodePublishVolume(
380-
context.Background(),
381-
&csi.NodePublishVolumeRequest{
382-
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
383-
VolumeCapability: nil,
384-
TargetPath: sc.TargetPath + "/target",
385-
Secrets: sc.Secrets.NodePublishVolumeSecret,
386-
},
387-
)
396+
req.VolumeCapability = nil
397+
398+
_, err := c.NodePublishVolume(context.Background(), req)
388399
Expect(err).To(HaveOccurred())
389400

390401
serverError, ok := status.FromError(err)
@@ -393,20 +404,9 @@ var _ = DescribeSanity("Node Service", func(sc *TestContext) {
393404
})
394405

395406
It("should fail when the volume is missing", func() {
396-
stagingPath := ""
397-
if nodeStageSupported {
398-
stagingPath = sc.StagingPath
399-
}
407+
req.VolumeId = sc.Config.IDGen.GenerateUniqueValidVolumeID()
400408

401-
_, err := c.NodePublishVolume(
402-
context.Background(),
403-
&csi.NodePublishVolumeRequest{
404-
VolumeId: sc.Config.IDGen.GenerateUniqueValidVolumeID(),
405-
VolumeCapability: TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
406-
StagingTargetPath: stagingPath,
407-
TargetPath: sc.TargetPath + "/target",
408-
Secrets: sc.Secrets.NodePublishVolumeSecret,
409-
})
409+
_, err := c.NodePublishVolume(context.Background(), req)
410410
Expect(err).To(HaveOccurred())
411411

412412
serverError, ok := status.FromError(err)

0 commit comments

Comments
 (0)