@@ -143,8 +143,10 @@ func TestNodePublishVolume(t *testing.T) {
143
143
}
144
144
tests := []struct {
145
145
desc string
146
+ setup func (* Driver )
146
147
req csi.NodePublishVolumeRequest
147
148
expectedErr error
149
+ cleanup func (* Driver )
148
150
}{
149
151
{
150
152
desc : "Volume capabilities missing" ,
@@ -169,6 +171,21 @@ func TestNodePublishVolume(t *testing.T) {
169
171
StagingTargetPath : sourceTest },
170
172
expectedErr : status .Error (codes .InvalidArgument , "Target path not provided" ),
171
173
},
174
+ {
175
+ desc : "[Error] Volume operation in progress" ,
176
+ setup : func (d * Driver ) {
177
+ d .volumeLocks .TryAcquire ("vol_1" )
178
+ },
179
+ req : csi.NodePublishVolumeRequest {VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
180
+ VolumeId : "vol_1" ,
181
+ TargetPath : targetTest ,
182
+ StagingTargetPath : sourceTest ,
183
+ Readonly : true },
184
+ expectedErr : status .Error (codes .Aborted , fmt .Sprintf (volumeOperationAlreadyExistsFmt , "vol_1" )),
185
+ cleanup : func (d * Driver ) {
186
+ d .volumeLocks .Release ("vol_1" )
187
+ },
188
+ },
172
189
{
173
190
desc : "Valid request read only" ,
174
191
req : csi.NodePublishVolumeRequest {VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
@@ -210,11 +227,17 @@ func TestNodePublishVolume(t *testing.T) {
210
227
}
211
228
212
229
for _ , test := range tests {
230
+ if test .setup != nil {
231
+ test .setup (d )
232
+ }
213
233
_ , err := d .NodePublishVolume (context .Background (), & test .req )
214
234
215
235
if ! reflect .DeepEqual (err , test .expectedErr ) {
216
236
t .Errorf ("Desc: %s - Unexpected error: %v - Expected: %v" , test .desc , err , test .expectedErr )
217
237
}
238
+ if test .cleanup != nil {
239
+ test .cleanup (d )
240
+ }
218
241
}
219
242
220
243
// Clean up
@@ -230,8 +253,10 @@ func TestNodePublishVolume(t *testing.T) {
230
253
func TestNodeUnpublishVolume (t * testing.T ) {
231
254
tests := []struct {
232
255
desc string
256
+ setup func (* Driver )
233
257
req csi.NodeUnpublishVolumeRequest
234
258
expectedErr error
259
+ cleanup func (* Driver )
235
260
}{
236
261
{
237
262
desc : "Volume ID missing" ,
@@ -243,6 +268,17 @@ func TestNodeUnpublishVolume(t *testing.T) {
243
268
req : csi.NodeUnpublishVolumeRequest {VolumeId : "vol_1" },
244
269
expectedErr : status .Error (codes .InvalidArgument , "Target path missing in request" ),
245
270
},
271
+ {
272
+ desc : "[Error] Volume operation in progress" ,
273
+ setup : func (d * Driver ) {
274
+ d .volumeLocks .TryAcquire ("vol_1" )
275
+ },
276
+ req : csi.NodeUnpublishVolumeRequest {TargetPath : targetTest , VolumeId : "vol_1" },
277
+ expectedErr : status .Error (codes .Aborted , fmt .Sprintf (volumeOperationAlreadyExistsFmt , "vol_1" )),
278
+ cleanup : func (d * Driver ) {
279
+ d .volumeLocks .Release ("vol_1" )
280
+ },
281
+ },
246
282
{
247
283
desc : "Valid request" ,
248
284
req : csi.NodeUnpublishVolumeRequest {TargetPath : "./abc.go" , VolumeId : "vol_1" },
@@ -263,11 +299,17 @@ func TestNodeUnpublishVolume(t *testing.T) {
263
299
}
264
300
265
301
for _ , test := range tests {
302
+ if test .setup != nil {
303
+ test .setup (d )
304
+ }
266
305
_ , err := d .NodeUnpublishVolume (context .Background (), & test .req )
267
306
268
307
if ! reflect .DeepEqual (err , test .expectedErr ) {
269
308
t .Errorf ("Unexpected error: %v" , err )
270
309
}
310
+ if test .cleanup != nil {
311
+ test .cleanup (d )
312
+ }
271
313
}
272
314
273
315
//Clean up
@@ -280,6 +322,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
280
322
}
281
323
282
324
func TestNodeStageVolume (t * testing.T ) {
325
+ volumeCap := csi.VolumeCapability_AccessMode {Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER }
283
326
testCases := []struct {
284
327
name string
285
328
testFunc func (t * testing.T )
@@ -325,13 +368,32 @@ func TestNodeStageVolume(t *testing.T) {
325
368
}
326
369
},
327
370
},
371
+ {
372
+ name : "Volume operation in progress" ,
373
+ testFunc : func (t * testing.T ) {
374
+ req := & csi.NodeStageVolumeRequest {
375
+ VolumeId : "unit-test" ,
376
+ StagingTargetPath : "unit-test" ,
377
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
378
+ }
379
+ d := NewFakeDriver ()
380
+ d .volumeLocks .TryAcquire ("unit-test" )
381
+ defer d .volumeLocks .Release ("unit-test" )
382
+ _ , err := d .NodeStageVolume (context .TODO (), req )
383
+ expectedErr := status .Error (codes .Aborted , fmt .Sprintf (volumeOperationAlreadyExistsFmt , "unit-test" ))
384
+ if ! reflect .DeepEqual (err , expectedErr ) {
385
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
386
+ }
387
+ },
388
+ },
328
389
}
329
390
for _ , tc := range testCases {
330
391
t .Run (tc .name , tc .testFunc )
331
392
}
332
393
}
333
394
334
395
func TestNodeUnstageVolume (t * testing.T ) {
396
+ volumeCap := csi.VolumeCapability_AccessMode {Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER }
335
397
testCases := []struct {
336
398
name string
337
399
testFunc func (t * testing.T )
@@ -362,6 +424,24 @@ func TestNodeUnstageVolume(t *testing.T) {
362
424
}
363
425
},
364
426
},
427
+ {
428
+ name : "Volume operation in progress" ,
429
+ testFunc : func (t * testing.T ) {
430
+ req := & csi.NodeStageVolumeRequest {
431
+ VolumeId : "unit-test" ,
432
+ StagingTargetPath : "unit-test" ,
433
+ VolumeCapability : & csi.VolumeCapability {AccessMode : & volumeCap },
434
+ }
435
+ d := NewFakeDriver ()
436
+ d .volumeLocks .TryAcquire ("unit-test" )
437
+ defer d .volumeLocks .Release ("unit-test" )
438
+ _ , err := d .NodeStageVolume (context .TODO (), req )
439
+ expectedErr := status .Error (codes .Aborted , fmt .Sprintf (volumeOperationAlreadyExistsFmt , "unit-test" ))
440
+ if ! reflect .DeepEqual (err , expectedErr ) {
441
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
442
+ }
443
+ },
444
+ },
365
445
{
366
446
name : "mount point not exist " ,
367
447
testFunc : func (t * testing.T ) {
0 commit comments