Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parent resource as a given #206

Merged
merged 1 commit into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 6 additions & 50 deletions reconcilers/reconcilers_test.go
Expand Up @@ -476,9 +476,8 @@ func TestChildReconciler(t *testing.T) {
}

rts := rtesting.SubReconcilerTestSuite{{
Name: "preserve no child",
Parent: resourceReady,
GivenObjects: []client.Object{},
Name: "preserve no child",
Parent: resourceReady,
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return defaultChildReconciler(c)
Expand Down Expand Up @@ -507,7 +506,6 @@ func TestChildReconciler(t *testing.T) {
SpecDie(func(d *dies.TestResourceSpecDie) {
d.AddField("foo", "bar")
}),
GivenObjects: []client.Object{},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return defaultChildReconciler(c)
Expand Down Expand Up @@ -644,7 +642,6 @@ func TestChildReconciler(t *testing.T) {
SpecDie(func(d *dies.TestResourceSpecDie) {
d.AddField("foo", "bar")
}),
GivenObjects: []client.Object{},
WithReactors: []rtesting.ReactionFunc{
rtesting.InduceFailure("create", "ConfigMap", rtesting.InduceFailureOpts{
Error: apierrs.NewAlreadyExists(schema.GroupResource{}, testName),
Expand Down Expand Up @@ -678,7 +675,6 @@ func TestChildReconciler(t *testing.T) {
SpecDie(func(d *dies.TestResourceSpecDie) {
d.AddField("foo", "bar")
}),
GivenObjects: []client.Object{},
APIGivenObjects: []client.Object{
configMapGiven,
},
Expand Down Expand Up @@ -748,7 +744,6 @@ func TestChildReconciler(t *testing.T) {
SpecDie(func(d *dies.TestResourceSpecDie) {
d.AddField("foo", "bar")
}),
GivenObjects: []client.Object{},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
r := defaultChildReconciler(c)
Expand All @@ -773,9 +768,8 @@ func TestChildReconciler(t *testing.T) {
configMapCreate,
},
}, {
Name: "error listing children",
Parent: resourceReady,
GivenObjects: []client.Object{},
Name: "error listing children",
Parent: resourceReady,
WithReactors: []rtesting.ReactionFunc{
rtesting.InduceFailure("list", "ConfigMapList"),
},
Expand All @@ -791,7 +785,6 @@ func TestChildReconciler(t *testing.T) {
SpecDie(func(d *dies.TestResourceSpecDie) {
d.AddField("foo", "bar")
}),
GivenObjects: []client.Object{},
WithReactors: []rtesting.ReactionFunc{
rtesting.InduceFailure("create", "ConfigMap"),
},
Expand Down Expand Up @@ -893,9 +886,8 @@ func TestChildReconciler(t *testing.T) {
},
ShouldErr: true,
}, {
Name: "error creating desired child",
Parent: resource,
GivenObjects: []client.Object{},
Name: "error creating desired child",
Parent: resource,
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
r := defaultChildReconciler(c)
Expand Down Expand Up @@ -935,9 +927,6 @@ func TestSequence(t *testing.T) {
rts := rtesting.SubReconcilerTestSuite{{
Name: "sub reconciler erred",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -954,9 +943,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "preserves result, Requeue",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return &reconcilers.SyncReconciler{
Expand All @@ -971,9 +957,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "preserves result, RequeueAfter",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -990,9 +973,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "ignores result on err",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1010,9 +990,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "Requeue + empty => Requeue",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1035,9 +1012,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "empty + Requeue => Requeue",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1060,9 +1034,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "RequeueAfter + empty => RequeueAfter",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1085,9 +1056,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "empty + RequeueAfter => RequeueAfter",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1110,9 +1078,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "RequeueAfter + Requeue => RequeueAfter",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1135,9 +1100,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "Requeue + RequeueAfter => RequeueAfter",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1160,9 +1122,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "RequeueAfter(1m) + RequeueAfter(2m) => RequeueAfter(1m)",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand All @@ -1185,9 +1144,6 @@ func TestSequence(t *testing.T) {
}, {
Name: "RequeueAfter(2m) + RequeueAfter(1m) => RequeueAfter(1m)",
Parent: resource,
GivenObjects: []client.Object{
resource,
},
Metadata: map[string]interface{}{
"SubReconciler": func(t *testing.T, c reconcilers.Config) reconcilers.SubReconciler {
return reconcilers.Sequence{
Expand Down
4 changes: 2 additions & 2 deletions testing/subreconciler.go
Expand Up @@ -119,13 +119,13 @@ func (tc *SubReconcilerTestCase) Run(t *testing.T, scheme *runtime.Scheme, facto
apiGivenObjects = append(apiGivenObjects, f.DeepCopyObject().(client.Object))
}

clientWrapper := NewFakeClient(scheme, givenObjects...)
clientWrapper := NewFakeClient(scheme, append(givenObjects, tc.Parent.DeepCopyObject().(client.Object))...)
for i := range tc.WithReactors {
// in reverse order since we prepend
reactor := tc.WithReactors[len(tc.WithReactors)-1-i]
clientWrapper.PrependReactor("*", "*", reactor)
}
apiReader := NewFakeClient(scheme, apiGivenObjects...)
apiReader := NewFakeClient(scheme, append(apiGivenObjects, tc.Parent.DeepCopyObject().(client.Object))...)
tracker := createTracker()
recorder := &eventRecorder{
events: []Event{},
Expand Down