Merge pull request #80418 from cwdsuzhou/July/fix_csi_attacher_ut

Fix csi attacher unit tests using t.Run()
This commit is contained in:
Kubernetes Prow Robot 2019-07-22 03:20:54 -07:00 committed by GitHub
commit 1cb3b5807e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -190,6 +190,7 @@ func TestAttacherAttach(t *testing.T) {
// attacher loop // attacher loop
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Logf("test case: %s", tc.name) t.Logf("test case: %s", tc.name)
plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil) plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@ -224,6 +225,7 @@ func TestAttacherAttach(t *testing.T) {
status.Attached = true status.Attached = true
} }
markVolumeAttached(t, csiAttacher.k8s, fakeWatcher, tc.attachID, status) markVolumeAttached(t, csiAttacher.k8s, fakeWatcher, tc.attachID, status)
})
} }
} }
@ -270,6 +272,7 @@ func TestAttacherAttachWithInline(t *testing.T) {
// attacher loop // attacher loop
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Logf("test case: %s", tc.name) t.Logf("test case: %s", tc.name)
plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil) plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@ -300,6 +303,7 @@ func TestAttacherAttachWithInline(t *testing.T) {
status.Attached = true status.Attached = true
} }
markVolumeAttached(t, csiAttacher.k8s, fakeWatcher, tc.attachID, status) markVolumeAttached(t, csiAttacher.k8s, fakeWatcher, tc.attachID, status)
})
} }
} }
@ -670,6 +674,7 @@ func TestAttacherWaitForVolumeAttachment(t *testing.T) {
} }
for i, tc := range testCases { for i, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil) plug, fakeWatcher, tmpDir, _ := newTestWatchPlugin(t, nil)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@ -716,6 +721,7 @@ func TestAttacherWaitForVolumeAttachment(t *testing.T) {
if err == nil && retID != attachID { if err == nil && retID != attachID {
t.Errorf("attacher.WaitForAttach not returning attachment ID") t.Errorf("attacher.WaitForAttach not returning attachment ID")
} }
})
} }
} }
@ -911,6 +917,7 @@ func TestAttacherDetach(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Logf("running test: %v", tc.name) t.Logf("running test: %v", tc.name)
plug, fakeWatcher, tmpDir, client := newTestWatchPlugin(t, nil) plug, fakeWatcher, tmpDir, client := newTestWatchPlugin(t, nil)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
@ -955,6 +962,7 @@ func TestAttacherDetach(t *testing.T) {
t.Errorf("expecting attachment not to be nil, but it is") t.Errorf("expecting attachment not to be nil, but it is")
} }
} }
})
} }
} }
@ -1087,6 +1095,7 @@ func TestAttacherMountDevice(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
t.Logf("Running test case: %s", tc.testName) t.Logf("Running test case: %s", tc.testName)
// Setup // Setup
@ -1125,7 +1134,7 @@ func TestAttacherMountDevice(t *testing.T) {
if !tc.shouldFail { if !tc.shouldFail {
t.Errorf("test should not fail, but error occurred: %v", err) t.Errorf("test should not fail, but error occurred: %v", err)
} }
continue return
} }
if err == nil && tc.shouldFail { if err == nil && tc.shouldFail {
t.Errorf("test should fail, but no error occurred") t.Errorf("test should fail, but no error occurred")
@ -1154,6 +1163,7 @@ func TestAttacherMountDevice(t *testing.T) {
t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags) t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags)
} }
} }
})
} }
} }
@ -1230,6 +1240,7 @@ func TestAttacherMountDeviceWithInline(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
t.Logf("Running test case: %s", tc.testName) t.Logf("Running test case: %s", tc.testName)
// Setup // Setup
@ -1268,7 +1279,7 @@ func TestAttacherMountDeviceWithInline(t *testing.T) {
if !tc.shouldFail { if !tc.shouldFail {
t.Errorf("test should not fail, but error occurred: %v", err) t.Errorf("test should not fail, but error occurred: %v", err)
} }
continue return
} }
if err == nil && tc.shouldFail { if err == nil && tc.shouldFail {
t.Errorf("test should fail, but no error occurred") t.Errorf("test should fail, but no error occurred")
@ -1294,6 +1305,7 @@ func TestAttacherMountDeviceWithInline(t *testing.T) {
t.Errorf("expected mount path: %s. got: %s", tc.deviceMountPath, vol.Path) t.Errorf("expected mount path: %s. got: %s", tc.deviceMountPath, vol.Path)
} }
} }
})
} }
} }
@ -1357,6 +1369,7 @@ func TestAttacherUnmountDevice(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
t.Logf("Running test case: %s", tc.testName) t.Logf("Running test case: %s", tc.testName)
// Setup // Setup
// Create a new attacher // Create a new attacher
@ -1407,7 +1420,7 @@ func TestAttacherUnmountDevice(t *testing.T) {
if !tc.shouldFail { if !tc.shouldFail {
t.Errorf("test should not fail, but error occurred: %v", err) t.Errorf("test should not fail, but error occurred: %v", err)
} }
continue return
} }
if err == nil && tc.shouldFail { if err == nil && tc.shouldFail {
t.Errorf("test should fail, but no error occurred") t.Errorf("test should fail, but no error occurred")
@ -1442,6 +1455,7 @@ func TestAttacherUnmountDevice(t *testing.T) {
t.Logf("json file %s was correctly removed", dataPath) t.Logf("json file %s was correctly removed", dataPath)
} }
} }
})
} }
} }