Skip to content

Commit 0bd2e62

Browse files
committed
Fix unit tests
1 parent e2d8e57 commit 0bd2e62

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

pkg/volume/csi/csi_block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func (m *csiBlockMapper) cleanupOrphanDeviceFiles() error {
466466
publishDir = publishPath
467467
}
468468
if err := os.Remove(publishDir); err != nil && !os.IsNotExist(err) {
469-
return errors.New(log("failed to publish directory [%s]: %v", publishDir, err))
469+
return errors.New(log("failed to remove publish directory [%s]: %v", publishDir, err))
470470
}
471471

472472
// Remove artifacts of NodeStage.

pkg/volume/csi/csi_block_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestBlockMapperSetupDeviceError(t *testing.T) {
304304
attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), string(nodeName))
305305
attachment := makeTestAttachment(attachID, nodeName, pvName)
306306
attachment.Status.Attached = true
307-
_, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
307+
_, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.Background(), attachment, metav1.CreateOptions{})
308308
if err != nil {
309309
t.Fatalf("failed to setup VolumeAttachment: %v", err)
310310
}
@@ -347,10 +347,10 @@ func TestBlockMapperMapPodDevice(t *testing.T) {
347347

348348
csiMapper.csiClient = setupClient(t, true)
349349

350-
attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), string(nodeName))
350+
attachID := getAttachmentName(csiMapper.volumeID, string(csiMapper.driverName), nodeName)
351351
attachment := makeTestAttachment(attachID, nodeName, pvName)
352352
attachment.Status.Attached = true
353-
_, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.TODO(), attachment, metav1.CreateOptions{})
353+
_, err = csiMapper.k8s.StorageV1().VolumeAttachments().Create(context.Background(), attachment, metav1.CreateOptions{})
354354
if err != nil {
355355
t.Fatalf("failed to setup VolumeAttachment: %v", err)
356356
}
@@ -483,6 +483,9 @@ func TestBlockMapperTearDownDevice(t *testing.T) {
483483
func TestVolumeSetupTeardown(t *testing.T) {
484484
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIBlockVolume, true)()
485485

486+
// Follow volume setup + teardown sequences at top of cs_block.go and set up / clean up one CSI block device.
487+
// Focus on testing that there were no leftover files present after the cleanup.
488+
486489
plug, tmpDir := newTestPlugin(t, nil)
487490
defer os.RemoveAll(tmpDir)
488491

@@ -505,7 +508,6 @@ func TestVolumeSetupTeardown(t *testing.T) {
505508
}
506509
t.Log("created attachement ", attachID)
507510

508-
// SetupDevice
509511
err = csiMapper.SetUpDevice()
510512
if err != nil {
511513
t.Fatalf("mapper failed to SetupDevice: %v", err)
@@ -521,7 +523,6 @@ func TestVolumeSetupTeardown(t *testing.T) {
521523
t.Errorf("csi server expected device path %s, got %s", stagingPath, svol.Path)
522524
}
523525

524-
// MapPodDevice
525526
path, err := csiMapper.MapPodDevice()
526527
if err != nil {
527528
t.Fatalf("mapper failed to GetGlobalMapPath: %v", err)
@@ -552,7 +553,6 @@ func TestVolumeSetupTeardown(t *testing.T) {
552553
t.Fatalf("unmapper failed to GetGlobalMapPath: %v", err)
553554
}
554555

555-
// UnmapDevice
556556
err = csiUnmapper.UnmapPodDevice()
557557
if err != nil {
558558
t.Errorf("unmapper failed to call UnmapPodDevice: %v", err)
@@ -566,7 +566,6 @@ func TestVolumeSetupTeardown(t *testing.T) {
566566
csiUnmapper = unmapper.(*csiBlockMapper)
567567
csiUnmapper.csiClient = csiMapper.csiClient
568568

569-
// TearDownDevice
570569
err = csiUnmapper.TearDownDevice(globalMapPath, "/dev/test")
571570
if err != nil {
572571
t.Fatal(err)

pkg/volume/csi/fake/fake_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ func (f *NodeClient) NodePublishVolume(ctx context.Context, req *csipb.NodePubli
192192
Path: req.GetTargetPath(),
193193
DeviceMountPath: req.GetStagingTargetPath(),
194194
VolumeContext: req.GetVolumeContext(),
195-
FSType: req.GetVolumeCapability().GetMount().GetFsType(),
196195
}
197196
if req.GetVolumeCapability().GetMount() != nil {
197+
publishedVolume.FSType = req.GetVolumeCapability().GetMount().FsType
198198
publishedVolume.MountFlags = req.GetVolumeCapability().GetMount().MountFlags
199199
}
200200
f.nodePublishedVolumes[req.GetVolumeId()] = publishedVolume

0 commit comments

Comments
 (0)