@@ -328,21 +328,6 @@ func Test_DisconnectNormalVolume(t *testing.T) {
328
328
329
329
func Test_DisconnectMultipathVolume (t * testing.T ) {
330
330
331
- tmpDir , err := ioutil .TempDir ("" , "" )
332
- if err != nil {
333
- t .Errorf ("can not create temp directory: %v" , err )
334
- return
335
- }
336
- sysBlockPath = tmpDir
337
- devPath = filepath .Join (tmpDir , "dev" )
338
- defer os .RemoveAll (tmpDir )
339
-
340
- err = preparePaths (tmpDir )
341
- if err != nil {
342
- t .Errorf ("can not create temp directories and files: %v" , err )
343
- return
344
- }
345
-
346
331
execWithTimeout = fakeExecWithTimeout
347
332
devicePath := multipathDevice
348
333
@@ -356,18 +341,33 @@ func Test_DisconnectMultipathVolume(t *testing.T) {
356
341
{"DisconnectMultipathVolume" , false , false , false , nil },
357
342
{"DisconnectMultipathVolumeFlushFailed" , false , false , true , fmt .Errorf ("error" )},
358
343
{"DisconnectMultipathVolumeFlushTimeout" , true , false , true , nil },
359
- {"DisconnectNonexistentMultipathVolume" , false , false , true , fmt .Errorf ("error" )},
344
+ {"DisconnectNonexistentMultipathVolume" , false , true , false , fmt .Errorf ("error" )},
360
345
}
361
346
for _ , tt := range tests {
362
347
t .Run (tt .name , func (t * testing.T ) {
348
+
349
+ tmpDir , err := ioutil .TempDir ("" , "" )
350
+ if err != nil {
351
+ t .Errorf ("can not create temp directory: %v" , err )
352
+ return
353
+ }
354
+ sysBlockPath = tmpDir
355
+ devPath = filepath .Join (tmpDir , "dev" )
356
+ defer os .RemoveAll (tmpDir )
357
+
358
+ err = preparePaths (tmpDir )
359
+ if err != nil {
360
+ t .Errorf ("can not create temp directories and files: %v" , err )
361
+ return
362
+ }
363
363
testExecWithTimeoutError = tt .cmdError
364
364
testCmdTimeout = tt .timeout
365
365
if tt .removeDevice {
366
366
os .RemoveAll (filepath .Join (sysBlockPath , devicePath ))
367
367
os .RemoveAll (devPath )
368
368
}
369
369
c := Connector {Multipath : true , DevicePath : devicePath }
370
- err : = DisconnectVolume (c )
370
+ err = DisconnectVolume (c )
371
371
if (err != nil ) != tt .wantErr {
372
372
t .Errorf ("DisconnectVolume() error = %v, wantErr %v" , err , tt .wantErr )
373
373
return
@@ -379,7 +379,7 @@ func Test_DisconnectMultipathVolume(t *testing.T) {
379
379
}
380
380
}
381
381
382
- if ! tt .removeDevice {
382
+ if ! tt .removeDevice && ! tt . wantErr {
383
383
for _ , s := range slaves {
384
384
deleteFile := filepath .Join (sysBlockPath , s , "device" , "delete" )
385
385
out , err := ioutil .ReadFile (deleteFile )
0 commit comments