Skip to content

Commit

Permalink
Add CR integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Dec 4, 2023
1 parent b9fb3a4 commit 9398703
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion internal/controllers/reconciliation/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/Azure/eno/internal/testutil"
)

// TODO: Add CR test
// TODO: Cover no-op update, assert on exact k8s api requests

type crudTestCase struct {
Name string
Expand All @@ -33,6 +33,7 @@ type crudTestCase struct {

var crudTests = []crudTestCase{
{
// TODO: This test has a rare race condition I think
Name: "strategic-merge", // will fail if non-strategic merge is used
Empty: &corev1.Service{},
Initial: &corev1.Service{
Expand Down Expand Up @@ -97,6 +98,36 @@ var crudTests = []crudTestCase{
}, svc.Ports)
},
},
{
Name: "cr-basics",
Empty: &testv1.TestResource{},
Initial: &testv1.TestResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cr",
Namespace: "default",
},
Spec: testv1.TestResourceSpec{
Values: []*testv1.TestValue{{Int: 1}, {Int: 2}},
},
},
AssertCreated: func(t *testing.T, obj client.Object) {
tr := obj.(*testv1.TestResource)
assert.Equal(t, []*testv1.TestValue{{Int: 1}, {Int: 2}}, tr.Spec.Values)
},
Updated: &testv1.TestResource{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cr",
Namespace: "default",
},
Spec: testv1.TestResourceSpec{
Values: []*testv1.TestValue{{Int: 2}},
},
},
AssertUpdated: func(t *testing.T, obj client.Object) {
tr := obj.(*testv1.TestResource)
assert.Equal(t, []*testv1.TestValue{{Int: 2}}, tr.Spec.Values)
},
},
}

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

0 comments on commit 9398703

Please sign in to comment.