2525 targetVacObject = & storagev1.VolumeAttributesClass {
2626 ObjectMeta : metav1.ObjectMeta {Name : targetVac },
2727 DriverName : testDriverName ,
28- Parameters : map [string ]string {
29- "iops" : "4567" ,
30- "csi.storage.k8s.io/pvc/name" : pvcName ,
31- "csi.storage.k8s.io/pvc/namespace" : pvcNamespace ,
32- "csi.storage.k8s.io/pv/name" : pvName ,
33- },
28+ Parameters : map [string ]string {"iops" : "4567" },
3429 }
3530)
3631
@@ -48,7 +43,7 @@ func TestModify(t *testing.T) {
4843 expectedCurrentVolumeAttributesClassName * string
4944 expectedPVVolumeAttributesClassName * string
5045 withExtraMetadata bool
51- expectedVacParams map [string ]string
46+ expectedMutableParams map [string ]string
5247 }{
5348 {
5449 name : "nothing to modify" ,
@@ -80,6 +75,7 @@ func TestModify(t *testing.T) {
8075 expectedModifyVolumeStatus : nil ,
8176 expectedCurrentVolumeAttributesClassName : & targetVac ,
8277 expectedPVVolumeAttributesClassName : & targetVac ,
78+ expectedMutableParams : map [string ]string {"iops" : "4567" },
8379 },
8480 {
8581 name : "modify volume success with extra metadata" ,
@@ -91,7 +87,7 @@ func TestModify(t *testing.T) {
9187 expectedCurrentVolumeAttributesClassName : & targetVac ,
9288 expectedPVVolumeAttributesClassName : & targetVac ,
9389 withExtraMetadata : true ,
94- expectedVacParams : map [string ]string {
90+ expectedMutableParams : map [string ]string {
9591 "iops" : "4567" ,
9692 "csi.storage.k8s.io/pvc/name" : basePVC .GetName (),
9793 "csi.storage.k8s.io/pvc/namespace" : basePVC .GetNamespace (),
@@ -104,12 +100,13 @@ func TestModify(t *testing.T) {
104100 test := tests [i ]
105101 t .Run (test .name , func (t * testing.T ) {
106102 // Setup
107- client := csi .NewMockClient (testDriverName , true , true , true , true , true , test . withExtraMetadata )
103+ client := csi .NewMockClient (testDriverName , true , true , true , true , true )
108104 initialObjects := []runtime.Object {test .pvc , test .pv , testVacObject }
109105 if test .vacExists {
110106 initialObjects = append (initialObjects , targetVacObject )
111107 }
112108 ctrlInstance := setupFakeK8sEnvironment (t , client , initialObjects )
109+ ctrlInstance .extraModifyMetadata = test .withExtraMetadata
113110
114111 // Action
115112 pvc , pv , err , modifyCalled := ctrlInstance .modify (test .pvc , test .pv )
@@ -138,15 +135,10 @@ func TestModify(t *testing.T) {
138135 t .Errorf ("expected VolumeAttributesClassName of pv to be %v, got %v" , * test .expectedPVVolumeAttributesClassName , * actualPVVolumeAttributesClassName )
139136 }
140137
141- if test .withExtraMetadata {
142- vacObj , err := ctrlInstance .vacLister .Get (* test .expectedPVVolumeAttributesClassName )
143- if err != nil {
144- t .Errorf ("failed to get VAC: %v" , err )
145- } else {
146- vacParams := vacObj .Parameters
147- if diff := cmp .Diff (test .expectedVacParams , vacParams ); diff != "" {
148- t .Errorf ("expected VAC parameters to be %v, got %v" , test .expectedVacParams , vacParams )
149- }
138+ if test .expectedMutableParams != nil {
139+ p := client .GetModifiedParameters ()
140+ if diff := cmp .Diff (test .expectedMutableParams , p ); diff != "" {
141+ t .Errorf ("expected mutable parameters to be %v, got %v" , test .expectedMutableParams , p )
150142 }
151143 }
152144 })
0 commit comments