Skip to content

Commit

Permalink
Don't mutate the object
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Dec 13, 2023
1 parent 5e4a8de commit dcd5696
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/controllers/reconciliation/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestCRUD(t *testing.T) {
require.NoError(t, err)

updatedObj := test.ApplyExternalUpdate(t, obj)
setPhase(updatedObj, "external-update")
updatedObj = setPhase(updatedObj, "external-update")
if err := downstream.Update(ctx, updatedObj); err != nil {
return err
}
Expand Down Expand Up @@ -279,10 +279,10 @@ func newSliceBuilder(t *testing.T, scheme *runtime.Scheme, test *crudTestCase) f
switch s.Spec.Image {
case "create":
obj = test.Initial.DeepCopyObject().(client.Object)
setPhase(obj, "create")
obj = setPhase(obj, "create")
case "update":
obj = test.Updated.DeepCopyObject().(client.Object)
setPhase(obj, "update")
obj = setPhase(obj, "update")
case "delete":
return []*apiv1.ResourceSlice{slice}
default:
Expand All @@ -301,13 +301,15 @@ func newSliceBuilder(t *testing.T, scheme *runtime.Scheme, test *crudTestCase) f
}
}

func setPhase(obj client.Object, phase string) {
anno := obj.GetAnnotations()
func setPhase(obj client.Object, phase string) client.Object {
copy := obj.DeepCopyObject().(client.Object)
anno := copy.GetAnnotations()
if anno == nil {
anno = map[string]string{}
}
anno["test-phase"] = phase
obj.SetAnnotations(anno)
copy.SetAnnotations(anno)
return copy
}

func getPhase(obj client.Object) string {
Expand Down

0 comments on commit dcd5696

Please sign in to comment.