Skip to content

Commit

Permalink
fix another test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
crenshaw-dev committed Jul 12, 2023
1 parent b28b3b0 commit 2662557
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,13 +1286,15 @@ func TestCreateApplications(t *testing.T) {
err = v1alpha1.AddToScheme(scheme)
assert.Nil(t, err)

for _, c := range []struct {
testCases := []struct {
name string
appSet v1alpha1.ApplicationSet
existsApps []v1alpha1.Application
apps []v1alpha1.Application
expected []v1alpha1.Application
}{
{
name: "no existing apps",
appSet: v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Expand All @@ -1318,10 +1320,14 @@ func TestCreateApplications(t *testing.T) {
Namespace: "namespace",
ResourceVersion: "1",
},
Spec: v1alpha1.ApplicationSpec{
Project: "default",
},
},
},
},
{
name: "existing apps",
appSet: v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Expand Down Expand Up @@ -1379,6 +1385,7 @@ func TestCreateApplications(t *testing.T) {
},
},
{
name: "existing apps with different project",
appSet: v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Expand Down Expand Up @@ -1435,39 +1442,42 @@ func TestCreateApplications(t *testing.T) {
},
},
},
} {
initObjs := []crtclient.Object{&c.appSet}
for _, a := range c.existsApps {
err = controllerutil.SetControllerReference(&c.appSet, &a, scheme)
assert.Nil(t, err)
initObjs = append(initObjs, &a)
}

client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(initObjs...).Build()
}

r := ApplicationSetReconciler{
Client: client,
Scheme: scheme,
Recorder: record.NewFakeRecorder(len(initObjs) + len(c.expected)),
}
for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
initObjs := []crtclient.Object{&c.appSet}
for _, a := range c.existsApps {
err = controllerutil.SetControllerReference(&c.appSet, &a, scheme)
assert.Nil(t, err)
initObjs = append(initObjs, &a)
}

err = r.createInCluster(context.TODO(), c.appSet, c.apps)
assert.Nil(t, err)
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(initObjs...).Build()

for _, obj := range c.expected {
got := &v1alpha1.Application{}
_ = client.Get(context.Background(), crtclient.ObjectKey{
Namespace: obj.Namespace,
Name: obj.Name,
}, got)
r := ApplicationSetReconciler{
Client: client,
Scheme: scheme,
Recorder: record.NewFakeRecorder(len(initObjs) + len(c.expected)),
}

err = controllerutil.SetControllerReference(&c.appSet, &obj, r.Scheme)
err = r.createInCluster(context.TODO(), c.appSet, c.apps)
assert.Nil(t, err)

assert.Equal(t, obj, *got)
}
}
for _, obj := range c.expected {
got := &v1alpha1.Application{}
_ = client.Get(context.Background(), crtclient.ObjectKey{
Namespace: obj.Namespace,
Name: obj.Name,
}, got)

err = controllerutil.SetControllerReference(&c.appSet, &obj, r.Scheme)
assert.Nil(t, err)

assert.Equal(t, obj, *got)
}
})
}
}

func TestDeleteInCluster(t *testing.T) {
Expand Down

0 comments on commit 2662557

Please sign in to comment.