@@ -282,6 +282,120 @@ func TestTranslateAzureFileInTreePVToCSI(t *testing.T) {
282
282
}
283
283
}
284
284
285
+ func TestTranslateCSIPVToInTree (t * testing.T ) {
286
+ translator := NewAzureFileCSITranslator ()
287
+
288
+ secretNamespace := "secretnamespace"
289
+ mp := make (map [string ]string )
290
+ mp ["shareName" ] = "unit-test"
291
+ cases := []struct {
292
+ name string
293
+ volume * corev1.PersistentVolume
294
+ expVol * corev1.PersistentVolume
295
+ expErr bool
296
+ }{
297
+ {
298
+ name : "empty volume" ,
299
+ expErr : true ,
300
+ },
301
+ {
302
+ name : "resource group empty" ,
303
+ volume : & corev1.PersistentVolume {
304
+ Spec : corev1.PersistentVolumeSpec {
305
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
306
+ CSI : & corev1.CSIPersistentVolumeSource {
307
+ NodeStageSecretRef : & corev1.SecretReference {
308
+ Name : "ut" ,
309
+ Namespace : secretNamespace ,
310
+ },
311
+ ReadOnly : true ,
312
+ VolumeAttributes : mp ,
313
+ },
314
+ },
315
+ },
316
+ },
317
+ expVol : & corev1.PersistentVolume {
318
+ Spec : corev1.PersistentVolumeSpec {
319
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
320
+ AzureFile : & corev1.AzureFilePersistentVolumeSource {
321
+ SecretName : "ut" ,
322
+ SecretNamespace : & secretNamespace ,
323
+ ReadOnly : true ,
324
+ ShareName : "unit-test" ,
325
+ },
326
+ },
327
+ },
328
+ },
329
+ expErr : false ,
330
+ },
331
+ {
332
+ name : "translate from volume handle error" ,
333
+ volume : & corev1.PersistentVolume {
334
+ Spec : corev1.PersistentVolumeSpec {
335
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
336
+ CSI : & corev1.CSIPersistentVolumeSource {
337
+ VolumeHandle : "unit-test" ,
338
+ ReadOnly : true ,
339
+ VolumeAttributes : mp ,
340
+ },
341
+ },
342
+ },
343
+ },
344
+ expErr : true ,
345
+ },
346
+ {
347
+ name : "translate from volume handle" ,
348
+ volume : & corev1.PersistentVolume {
349
+ ObjectMeta : metav1.ObjectMeta {
350
+ Name : "file.csi.azure.com-sharename" ,
351
+ },
352
+ Spec : corev1.PersistentVolumeSpec {
353
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
354
+ CSI : & corev1.CSIPersistentVolumeSource {
355
+ VolumeHandle : "rg#st#pvc-file-dynamic#diskname.vhd" ,
356
+ ReadOnly : true ,
357
+ VolumeAttributes : mp ,
358
+ },
359
+ },
360
+ },
361
+ },
362
+ expVol : & corev1.PersistentVolume {
363
+ ObjectMeta : metav1.ObjectMeta {
364
+ Name : "file.csi.azure.com-sharename" ,
365
+ Annotations : map [string ]string {resourceGroupAnnotation : "rg" },
366
+ },
367
+ Spec : corev1.PersistentVolumeSpec {
368
+ PersistentVolumeSource : corev1.PersistentVolumeSource {
369
+ AzureFile : & corev1.AzureFilePersistentVolumeSource {
370
+ SecretName : "azure-storage-account-st-secret" ,
371
+ ShareName : "pvc-file-dynamic" ,
372
+ ReadOnly : true ,
373
+ },
374
+ },
375
+ },
376
+ },
377
+ expErr : false ,
378
+ },
379
+ }
380
+
381
+ for _ , tc := range cases {
382
+ t .Logf ("Testing %v" , tc .name )
383
+ got , err := translator .TranslateCSIPVToInTree (tc .volume )
384
+ if err != nil && ! tc .expErr {
385
+ t .Errorf ("Did not expect error but got: %v" , err )
386
+ }
387
+
388
+ if err == nil && tc .expErr {
389
+ t .Errorf ("Expected error, but did not get one." )
390
+ }
391
+
392
+ if ! reflect .DeepEqual (got , tc .expVol ) {
393
+ t .Errorf ("Got parameters: %v, expected :%v" , got , tc .expVol )
394
+ }
395
+ }
396
+
397
+ }
398
+
285
399
func TestGetStorageAccount (t * testing.T ) {
286
400
tests := []struct {
287
401
secretName string
0 commit comments