@@ -2,7 +2,7 @@ package modifycontroller
22
33import (
44 "context"
5- "reflect "
5+ "errors "
66 "testing"
77 "time"
88
3737 targetVac = "target-vac"
3838 testDriverName = "mock"
3939 infeasibleErr = status .Errorf (codes .InvalidArgument , "Parameters in VolumeAttributesClass is invalid" )
40- finalErr = status .Errorf (codes .Internal , "Final error" )
4140 pvcConditionInProgress = v1.PersistentVolumeClaimCondition {
4241 Type : v1 .PersistentVolumeClaimVolumeModifyingVolume ,
4342 Status : v1 .ConditionTrue ,
@@ -83,7 +82,7 @@ func TestMarkControllerModifyVolumeStatus(t *testing.T) {
8382 pvc : basePVC .Get (),
8483 expectedPVC : basePVC .WithModifyVolumeStatus (v1 .PersistentVolumeClaimModifyVolumeInfeasible ).Get (),
8584 expectedConditions : []v1.PersistentVolumeClaimCondition {pvcConditionInfeasible },
86- expectedErr : infeasibleErr ,
85+ expectedErr : nil ,
8786 testFunc : func (pvc * v1.PersistentVolumeClaim , ctrl * modifyController ) (* v1.PersistentVolumeClaim , error ) {
8887 return ctrl .markControllerModifyVolumeStatus (pvc , v1 .PersistentVolumeClaimModifyVolumeInfeasible , infeasibleErr )
8988 },
@@ -126,14 +125,14 @@ func TestMarkControllerModifyVolumeStatus(t *testing.T) {
126125 ctrlInstance , _ := controller .(* modifyController )
127126
128127 pvc , err = tc .testFunc (pvc , ctrlInstance )
129- if err != nil && ! reflect . DeepEqual ( tc .expectedErr , err ) {
130- t .Errorf ("Expected error to be %v but got %v" , tc .expectedErr , err )
128+ if ! errors . Is ( err , tc .expectedErr ) {
129+ t .Errorf ("expected error: %v, got: %v" , tc .expectedErr , err )
131130 }
132131
133132 realStatus := pvc .Status .ModifyVolumeStatus .Status
134133 expectedStatus := tc .expectedPVC .Status .ModifyVolumeStatus .Status
135- if ! reflect . DeepEqual ( realStatus , expectedStatus ) {
136- t .Errorf ("expected modify volume status %+v got %+v " , expectedStatus , realStatus )
134+ if diff := cmp . Diff ( expectedStatus , realStatus ); diff != "" {
135+ t .Errorf ("unexpected modify volume status (-want + got): \n %s " , diff )
137136 }
138137
139138 realConditions := pvc .Status .Conditions
@@ -167,8 +166,6 @@ func TestUpdateConditionBasedOnError(t *testing.T) {
167166 client := csi .NewMockClient ("foo" , true , true , true , true , true , false )
168167 driverName , _ := client .GetDriverName (context .TODO ())
169168
170- pvc := test .pvc
171-
172169 var initialObjects []runtime.Object
173170 initialObjects = append (initialObjects , test .pvc )
174171
@@ -185,9 +182,9 @@ func TestUpdateConditionBasedOnError(t *testing.T) {
185182
186183 ctrlInstance , _ := controller .(* modifyController )
187184
188- pvc , err = ctrlInstance .updateConditionBasedOnError (tc .pvc , err )
189- if err != nil && ! reflect . DeepEqual ( tc .expectedErr , err ) {
190- t .Errorf ("Expected error to be %v but got %v" , tc .expectedErr , err )
185+ pvc , err : = ctrlInstance .updateConditionBasedOnError (tc .pvc , err )
186+ if ! errors . Is ( err , tc .expectedErr ) {
187+ t .Errorf ("expected error: %v, got: %v" , tc .expectedErr , err )
191188 }
192189
193190 if ! testutil .CompareConditions (pvc .Status .Conditions , tc .expectedConditions ) {
@@ -254,20 +251,20 @@ func TestMarkControllerModifyVolumeCompleted(t *testing.T) {
254251 ctrlInstance , _ := controller .(* modifyController )
255252
256253 actualPVC , pv , err := ctrlInstance .markControllerModifyVolumeCompleted (tc .pvc , tc .pv )
257- if err != nil && ! reflect . DeepEqual ( tc .expectedErr , err ) {
258- t .Errorf ("Expected error to be %v but got %v" , tc .expectedErr , err )
254+ if ! errors . Is ( err , tc .expectedErr ) {
255+ t .Errorf ("expected error: %v, got: %v" , tc .expectedErr , err )
259256 }
260257
261258 if len (actualPVC .Status .Conditions ) == 0 {
262259 actualPVC .Status .Conditions = []v1.PersistentVolumeClaimCondition {}
263260 }
264261
265262 if diff := cmp .Diff (tc .expectedPVC , actualPVC ); diff != "" {
266- t .Errorf ("expected pvc %+v got %+v, diff is: %v" , tc . expectedPVC , actualPVC , diff )
263+ t .Errorf ("unexpected pvc (-want +got): \n %s" , diff )
267264 }
268265
269266 if diff := cmp .Diff (tc .expectedPV , pv ); diff != "" {
270- t .Errorf ("expected pvc %+v got %+v, diff is: %v" , tc . expectedPV , pv , diff )
267+ t .Errorf ("unexpected pv (-want +got): \n %s" , diff )
271268 }
272269 })
273270 }
0 commit comments