@@ -58,14 +58,14 @@ type testCase struct {
58
58
initialObjects []runtime.Object
59
59
// Args for the populator pod
60
60
populatorArgs func (b bool , u * unstructured.Unstructured ) ([]string , error )
61
+ // Provider specific PVC prime creation function
62
+ pvcPrimeCreateFn func (context.Context , PopulatorParams ) (* corev1.PersistentVolumeClaim , error )
61
63
// Provider specific data population function
62
64
populateFn func (context.Context , PopulatorParams ) error
63
65
// Provider specific data population completeness check function, return true when data transfer gets completed.
64
66
populateCompleteFn func (context.Context , PopulatorParams ) (bool , error )
65
67
// The original PVC gets deleted or not
66
68
pvcDeleted bool
67
- // PvcPrimeMutator is the mutator function for pvcPrime
68
- pvcPrimeMutator func (PvcPrimeMutatorParams ) (* v1.PersistentVolumeClaim , error )
69
69
// Expected errors
70
70
expectedResult error
71
71
// Expected keys in the notifyMap
@@ -105,7 +105,7 @@ const (
105
105
testProvisioner = "test.provisioner"
106
106
testPopulationOperationStartFailed = "Test populate operation start failed"
107
107
testPopulateCompleteFailed = "Test populate operation complete failed"
108
- testMutatePVCPrimeFailed = "Test mutate pvcPrime failed"
108
+ testPvcPrimeCreateFailed = "Test create pvcPrime failed"
109
109
dataSourceKey = "unstructured/" + testPvcNamespace + "/" + testDataSourceName
110
110
storageClassKey = "sc/" + testStorageClassName
111
111
podKey = "pod/" + testVpWorkingNamespace + "/" + testPodName
@@ -252,18 +252,18 @@ func populateCompleteSuccess(ctx context.Context, p PopulatorParams) (bool, erro
252
252
return true , nil
253
253
}
254
254
255
- func pvcPrimeMutateAccessModeRWX (mp PvcPrimeMutatorParams ) (* v1.PersistentVolumeClaim , error ) {
256
- accessMode := v1 .ReadWriteMany
257
- mp .PvcPrime .Spec .AccessModes [0 ] = accessMode
258
- return mp .PvcPrime , nil
255
+ func pvcPrimeCreateError (ctx context.Context , p PopulatorParams ) (* corev1.PersistentVolumeClaim , error ) {
256
+ return nil , fmt .Errorf (testPvcPrimeCreateFailed )
259
257
}
260
258
261
- func pvcPrimeMutateError ( mp PvcPrimeMutatorParams ) (* v1 .PersistentVolumeClaim , error ) {
262
- return mp . PvcPrime , fmt . Errorf ( testMutatePVCPrimeFailed )
259
+ func pvcPrimeCreateNil ( ctx context. Context , p PopulatorParams ) (* corev1 .PersistentVolumeClaim , error ) {
260
+ return nil , nil
263
261
}
264
262
265
- func pvcPrimeMutatePVCPrimeNil (mp PvcPrimeMutatorParams ) (* v1.PersistentVolumeClaim , error ) {
266
- return nil , nil
263
+ func pvcPrimeCreateSuccess (pvcPrime * corev1.PersistentVolumeClaim ) func (ctx context.Context , p PopulatorParams ) (* corev1.PersistentVolumeClaim , error ) {
264
+ return func (ctx context.Context , p PopulatorParams ) (* corev1.PersistentVolumeClaim , error ) {
265
+ return pvcPrime , nil
266
+ }
267
267
}
268
268
269
269
func initTest (test testCase ) (
@@ -310,19 +310,14 @@ func initTest(test testCase) (
310
310
}
311
311
}
312
312
313
- var providerFunctionConfig * ProviderFunctionConfig
313
+ var providerFunctionConfig * ProviderFunctionConfig = & ProviderFunctionConfig {}
314
314
if test .populateFn != nil || test .populateCompleteFn != nil {
315
- providerFunctionConfig = & ProviderFunctionConfig {
316
- PopulateFn : test .populateFn ,
317
- PopulateCompleteFn : test .populateCompleteFn ,
318
- }
315
+ providerFunctionConfig .PopulateFn = test .populateFn
316
+ providerFunctionConfig .PopulateCompleteFn = test .populateCompleteFn
319
317
}
320
318
321
- var mutatorConfig * MutatorConfig
322
- if test .pvcPrimeMutator != nil {
323
- mutatorConfig = & MutatorConfig {
324
- PvcPrimeMutator : test .pvcPrimeMutator ,
325
- }
319
+ if test .pvcPrimeCreateFn != nil {
320
+ providerFunctionConfig .CreatePVCPrimeFn = test .pvcPrimeCreateFn
326
321
}
327
322
328
323
c := & controller {
@@ -350,7 +345,6 @@ func initTest(test testCase) (
350
345
referenceGrantSynced : referenceGrants .Informer ().HasSynced ,
351
346
podConfig : podConfig ,
352
347
providerFunctionConfig : providerFunctionConfig ,
353
- mutatorConfig : mutatorConfig ,
354
348
}
355
349
return c , pvcInformer , unstInformer , scInformer , podInformer , pvInformer
356
350
}
@@ -367,7 +361,7 @@ func compareResult(want error, got error) bool {
367
361
368
362
func compareNotifyMap (want []string , got map [string ]* stringSet ) error {
369
363
if len (want ) != len (got ) {
370
- return fmt .Errorf ("The number of keys expected is different from actual. Expect %v, got %v" , len (want ), len (got ))
364
+ return fmt .Errorf ("The number of keys expected is different from actual. Expect %v, got %v. Want %v: Got: %v " , len (want ), len (got ), want , got )
371
365
}
372
366
for _ , key := range want {
373
367
if got [key ] == nil {
@@ -682,10 +676,10 @@ func TestSyncPvcWithPopulatorPod(t *testing.T) {
682
676
ust (),
683
677
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
684
678
},
685
- populatorArgs : populatorArgs ,
686
- pvcPrimeMutator : pvcPrimeMutateAccessModeRWX ,
687
- expectedResult : nil ,
688
- expectedKeys : []string {podKey , pvcPrimeKey },
679
+ populatorArgs : populatorArgs ,
680
+ pvcPrimeCreateFn : pvcPrimeCreateSuccess ( pvc ( testPvcPrimeName , testVpWorkingNamespace , "" , testStorageClassName , "" , "" , [] string {}, nil , "" , v1 . ReadWriteMany )) ,
681
+ expectedResult : nil ,
682
+ expectedKeys : []string {podKey , pvcPrimeKey },
689
683
expectedObjects : & vpObjects {
690
684
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer , vpFinalizer },
691
685
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
@@ -710,10 +704,10 @@ func TestSyncPvcWithPopulatorPod(t *testing.T) {
710
704
ust (),
711
705
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
712
706
},
713
- populatorArgs : populatorArgs ,
714
- pvcPrimeMutator : pvcPrimeMutateError ,
715
- expectedResult : fmt .Errorf (testMutatePVCPrimeFailed ),
716
- expectedKeys : []string {podKey , pvcPrimeKey },
707
+ populatorArgs : populatorArgs ,
708
+ pvcPrimeCreateFn : pvcPrimeCreateError ,
709
+ expectedResult : fmt .Errorf (testPvcPrimeCreateFailed ),
710
+ expectedKeys : []string {podKey , pvcPrimeKey },
717
711
expectedObjects : & vpObjects {
718
712
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer },
719
713
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
@@ -730,10 +724,10 @@ func TestSyncPvcWithPopulatorPod(t *testing.T) {
730
724
ust (),
731
725
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
732
726
},
733
- populatorArgs : populatorArgs ,
734
- pvcPrimeMutator : pvcPrimeMutatePVCPrimeNil ,
735
- expectedResult : fmt .Errorf ("pvcPrime must not be nil" ),
736
- expectedKeys : []string {podKey , pvcPrimeKey },
727
+ populatorArgs : populatorArgs ,
728
+ pvcPrimeCreateFn : pvcPrimeCreateNil ,
729
+ expectedResult : fmt .Errorf ("pvcPrime must not be nil" ),
730
+ expectedKeys : []string {podKey , pvcPrimeKey },
737
731
expectedObjects : & vpObjects {
738
732
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer },
739
733
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
@@ -1076,10 +1070,10 @@ func TestSyncPvcWithProviderImplementation(t *testing.T) {
1076
1070
ust (),
1077
1071
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
1078
1072
},
1079
- pvcPrimeMutator : pvcPrimeMutateAccessModeRWX ,
1080
- populateFn : populateOperationStartError ,
1081
- expectedResult : nil ,
1082
- expectedKeys : []string {pvcPrimeKey },
1073
+ pvcPrimeCreateFn : pvcPrimeCreateSuccess ( pvc ( testPvcPrimeName , testVpWorkingNamespace , "" , testStorageClassName , "" , "" , [] string {}, nil , "" , v1 . ReadWriteMany )) ,
1074
+ populateFn : populateOperationStartError ,
1075
+ expectedResult : nil ,
1076
+ expectedKeys : []string {pvcPrimeKey },
1083
1077
expectedObjects : & vpObjects {
1084
1078
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer , vpFinalizer },
1085
1079
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
@@ -1103,10 +1097,10 @@ func TestSyncPvcWithProviderImplementation(t *testing.T) {
1103
1097
ust (),
1104
1098
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
1105
1099
},
1106
- pvcPrimeMutator : pvcPrimeMutateError ,
1107
- populateFn : populateOperationStartError ,
1108
- expectedResult : fmt .Errorf (testMutatePVCPrimeFailed ),
1109
- expectedKeys : []string {pvcPrimeKey },
1100
+ pvcPrimeCreateFn : pvcPrimeCreateError ,
1101
+ populateFn : populateOperationStartError ,
1102
+ expectedResult : fmt .Errorf (testPvcPrimeCreateFailed ),
1103
+ expectedKeys : []string {pvcPrimeKey },
1110
1104
expectedObjects : & vpObjects {
1111
1105
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer },
1112
1106
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
@@ -1123,10 +1117,10 @@ func TestSyncPvcWithProviderImplementation(t *testing.T) {
1123
1117
ust (),
1124
1118
sc (testStorageClassName , storagev1 .VolumeBindingImmediate ),
1125
1119
},
1126
- pvcPrimeMutator : pvcPrimeMutatePVCPrimeNil ,
1127
- populateFn : populateOperationStartError ,
1128
- expectedResult : fmt .Errorf ("pvcPrime must not be nil" ),
1129
- expectedKeys : []string {pvcPrimeKey },
1120
+ pvcPrimeCreateFn : pvcPrimeCreateNil ,
1121
+ populateFn : populateOperationStartError ,
1122
+ expectedResult : fmt .Errorf ("pvcPrime must not be nil" ),
1123
+ expectedKeys : []string {pvcPrimeKey },
1130
1124
expectedObjects : & vpObjects {
1131
1125
pvc : pvc (testPvcName , testPvcNamespace , "" , testStorageClassName , "" , testPvcUid , []string {pvFinalizer },
1132
1126
dsf (testApiGroup , testDatasourceKind , testDataSourceName , testPvcNamespace ), "" , v1 .ReadWriteOnce ),
0 commit comments