Skip to content

Commit

Permalink
Probably fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Dec 13, 2023
1 parent 6da6acf commit 217ba72
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions internal/controllers/reconciliation/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (

// TODO: Assert on status

// TODO: Test renaming

type crudTestCase struct {
Name string
Empty, Initial, Updated client.Object
Expand Down Expand Up @@ -182,15 +180,13 @@ func TestCRUD(t *testing.T) {
comp.Spec.Synthesizer.Name = syn.Name
require.NoError(t, upstream.Create(ctx, comp))

var lastResourceVersion string
t.Run("creation", func(t *testing.T) {
var obj client.Object
testutil.Eventually(t, func() bool {
obj, err = test.Get(downstream)
return err == nil
})
test.AssertCreated(t, obj)
lastResourceVersion = obj.GetResourceVersion()
})

if test.ApplyExternalUpdate != nil {
Expand All @@ -200,24 +196,20 @@ func TestCRUD(t *testing.T) {
require.NoError(t, err)

updatedObj := test.ApplyExternalUpdate(t, obj)
setPhase(updatedObj, "external-update")
if err := downstream.Update(ctx, updatedObj); err != nil {
return err
}

lastResourceVersion = updatedObj.GetResourceVersion()
t.Logf("external update version %s", lastResourceVersion)
return nil
})
require.NoError(t, err)

// wait for this write to hit the informer cache
// in real life things will converge eventually, but here we expect writes to be ordered
testutil.Eventually(t, func() bool {
obj, err := test.Get(downstream)
if err != nil || obj.GetResourceVersion() != lastResourceVersion {
return false
}
lastResourceVersion = obj.GetResourceVersion()
return true
return err == nil && getPhase(obj) == "external-update"
})
})
}
Expand All @@ -228,7 +220,7 @@ func TestCRUD(t *testing.T) {
var obj client.Object
testutil.Eventually(t, func() bool {
obj, err = test.Get(downstream)
return err == nil && obj.GetResourceVersion() != lastResourceVersion
return err == nil && getPhase(obj) == "update"
})
test.AssertUpdated(t, obj)
})
Expand Down Expand Up @@ -287,8 +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")
case "update":
obj = test.Updated.DeepCopyObject().(client.Object)
setPhase(obj, "update")
case "delete":
return []*apiv1.ResourceSlice{slice}
default:
Expand All @@ -306,3 +300,20 @@ func newSliceBuilder(t *testing.T, scheme *runtime.Scheme, test *crudTestCase) f
return []*apiv1.ResourceSlice{slice}
}
}

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

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

0 comments on commit 217ba72

Please sign in to comment.