@@ -240,6 +240,144 @@ func TestNodeUnpublishVolume(t *testing.T) {
240
240
assert .NoError (t , err )
241
241
}
242
242
243
+ func TestNodeStageVolume (t * testing.T ) {
244
+ testCases := []struct {
245
+ name string
246
+ testFunc func (t * testing.T )
247
+ }{
248
+ {
249
+ name : "Volume ID missing" ,
250
+ testFunc : func (t * testing.T ) {
251
+ req := & csi.NodeStageVolumeRequest {}
252
+ d := NewFakeDriver ()
253
+ _ , err := d .NodeStageVolume (context .TODO (), req )
254
+ expectedErr := status .Error (codes .InvalidArgument , "Volume ID missing in request" )
255
+ if ! reflect .DeepEqual (err , expectedErr ) {
256
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
257
+ }
258
+ },
259
+ },
260
+ {
261
+ name : "Staging target not provided" ,
262
+ testFunc : func (t * testing.T ) {
263
+ req := & csi.NodeStageVolumeRequest {
264
+ VolumeId : "unit-test" ,
265
+ }
266
+ d := NewFakeDriver ()
267
+ _ , err := d .NodeStageVolume (context .TODO (), req )
268
+ expectedErr := status .Error (codes .InvalidArgument , "Staging target not provided" )
269
+ if ! reflect .DeepEqual (err , expectedErr ) {
270
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
271
+ }
272
+ },
273
+ },
274
+ {
275
+ name : "Volume capability missing" ,
276
+ testFunc : func (t * testing.T ) {
277
+ req := & csi.NodeStageVolumeRequest {
278
+ VolumeId : "unit-test" ,
279
+ StagingTargetPath : "unit-test" ,
280
+ }
281
+ d := NewFakeDriver ()
282
+ _ , err := d .NodeStageVolume (context .TODO (), req )
283
+ expectedErr := status .Error (codes .InvalidArgument , "Volume capability not provided" )
284
+ if ! reflect .DeepEqual (err , expectedErr ) {
285
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
286
+ }
287
+ },
288
+ },
289
+ {
290
+ name : "volume mount sensitive fail" ,
291
+ testFunc : func (t * testing.T ) {
292
+ attrib := make (map [string ]string )
293
+ attrib ["containername" ] = "ut-container"
294
+ attrib ["server" ] = "blob-endpoint"
295
+ attrib ["protocol" ] = "nfs"
296
+ secret := make (map [string ]string )
297
+ secret ["accountname" ] = "unit-test"
298
+ accessType := csi.VolumeCapability_Mount {}
299
+ req := & csi.NodeStageVolumeRequest {
300
+ VolumeId : "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41" ,
301
+ StagingTargetPath : "right_mount" ,
302
+ VolumeContext : attrib ,
303
+ Secrets : secret ,
304
+ VolumeCapability : & csi.VolumeCapability {
305
+ AccessType : & accessType ,
306
+ },
307
+ }
308
+ d := NewFakeDriver ()
309
+ fakeMounter := & fakeMounter {}
310
+ d .mounter = & mount.SafeFormatAndMount {
311
+ Interface : fakeMounter ,
312
+ }
313
+ _ , err := d .NodeStageVolume (context .TODO (), req )
314
+ expectedErr := status .Error (codes .Internal , "volume(rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41) mount \" blob-endpoint:/unit-test/ut-container\" on \" right_mount\" failed with fake MountSensitive: source error" )
315
+ if ! reflect .DeepEqual (err , expectedErr ) {
316
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
317
+ }
318
+ // Clean up
319
+ err = os .RemoveAll (req .StagingTargetPath )
320
+ assert .NoError (t , err )
321
+ },
322
+ },
323
+ }
324
+ for _ , tc := range testCases {
325
+ t .Run (tc .name , tc .testFunc )
326
+ }
327
+ }
328
+
329
+ func TestNodeUnstageVolume (t * testing.T ) {
330
+ testCases := []struct {
331
+ name string
332
+ testFunc func (t * testing.T )
333
+ }{
334
+ {
335
+ name : "Volume ID missing" ,
336
+ testFunc : func (t * testing.T ) {
337
+ req := & csi.NodeUnstageVolumeRequest {}
338
+ d := NewFakeDriver ()
339
+ _ , err := d .NodeUnstageVolume (context .TODO (), req )
340
+ expectedErr := status .Error (codes .InvalidArgument , "Volume ID not provided" )
341
+ if ! reflect .DeepEqual (err , expectedErr ) {
342
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
343
+ }
344
+ },
345
+ },
346
+ {
347
+ name : "staging target missing" ,
348
+ testFunc : func (t * testing.T ) {
349
+ req := & csi.NodeUnstageVolumeRequest {
350
+ VolumeId : "unit-test" ,
351
+ }
352
+ d := NewFakeDriver ()
353
+ _ , err := d .NodeUnstageVolume (context .TODO (), req )
354
+ expectedErr := status .Error (codes .InvalidArgument , "Staging target not provided" )
355
+ if ! reflect .DeepEqual (err , expectedErr ) {
356
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
357
+ }
358
+ },
359
+ },
360
+ {
361
+ name : "mount point not exist " ,
362
+ testFunc : func (t * testing.T ) {
363
+ req := & csi.NodeUnstageVolumeRequest {
364
+ VolumeId : "unit-test" ,
365
+ StagingTargetPath : "./unit-test" ,
366
+ }
367
+ d := NewFakeDriver ()
368
+ _ , err := d .NodeUnstageVolume (context .TODO (), req )
369
+ expectedErr := error (nil )
370
+ if ! reflect .DeepEqual (err , expectedErr ) {
371
+ t .Errorf ("actualErr: (%v), expectedErr: (%v)" , err , expectedErr )
372
+ }
373
+ },
374
+ },
375
+ }
376
+ for _ , tc := range testCases {
377
+ t .Run (tc .name , tc .testFunc )
378
+ }
379
+ }
380
+
243
381
func makeDir (pathname string ) error {
244
382
err := os .MkdirAll (pathname , os .FileMode (0755 ))
245
383
if err != nil {
@@ -278,3 +416,23 @@ func TestNewSafeMounter(t *testing.T) {
278
416
assert .NotNil (t , resp )
279
417
assert .Nil (t , err )
280
418
}
419
+
420
+ func TestNodeGetVolumeStats (t * testing.T ) {
421
+ d := NewFakeDriver ()
422
+ req := csi.NodeGetVolumeStatsRequest {}
423
+ resp , err := d .NodeGetVolumeStats (context .Background (), & req )
424
+ assert .Nil (t , resp )
425
+ if ! reflect .DeepEqual (err , status .Error (codes .Unimplemented , "" )) {
426
+ t .Errorf ("Unexpected error: %v" , err )
427
+ }
428
+ }
429
+
430
+ func TestNodeExpandVolume (t * testing.T ) {
431
+ d := NewFakeDriver ()
432
+ req := csi.NodeExpandVolumeRequest {}
433
+ resp , err := d .NodeExpandVolume (context .Background (), & req )
434
+ assert .Nil (t , resp )
435
+ if ! reflect .DeepEqual (err , status .Error (codes .Unimplemented , "NodeExpandVolume is not yet implemented" )) {
436
+ t .Errorf ("Unexpected error: %v" , err )
437
+ }
438
+ }
0 commit comments