From 77926e7d7dcbad44e316b083cd0bf9ecdb7b016c Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Mon, 29 Apr 2024 16:14:23 +0100 Subject: [PATCH] Add integration tests. --- controllers/kuadrant_controller_test.go | 103 ++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 controllers/kuadrant_controller_test.go diff --git a/controllers/kuadrant_controller_test.go b/controllers/kuadrant_controller_test.go new file mode 100644 index 000000000..c92a5dcd4 --- /dev/null +++ b/controllers/kuadrant_controller_test.go @@ -0,0 +1,103 @@ +//go:build integration + +package controllers + +import ( + authorinov1beta1 "github.com/kuadrant/authorino-operator/api/v1beta1" + kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" + "github.com/kuadrant/kuadrant-operator/pkg/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "k8s.io/utils/ptr" + "reflect" + "sigs.k8s.io/controller-runtime/pkg/client" + "time" +) + +var _ = Describe("Kuadrant controller", func() { + var ( + testNamespace string + ) + const ( + kuadrant = "kuadrant-sample" + afterEachTimeOut = NodeTimeout(3 * time.Minute) + ) + Context("Reconcile Authorino resources", func() { + BeforeEach(func(ctx SpecContext) { + testNamespace = CreateNamespaceWithContext(ctx) + ApplyKuadrantCR(testNamespace) + }) + AfterEach(func(ctx SpecContext) { + DeleteNamespaceCallbackWithContext(ctx, testNamespace) + }, afterEachTimeOut) + + It("Should copy configuration from Kuadrant CR to Authorino CR", func(ctx SpecContext) { + kObj := &kuadrantv1beta1.Kuadrant{} + aObj := &authorinov1beta1.Authorino{} + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: common.AuthorinoName, Namespace: testNamespace}, aObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + var tmp *int32 + Expect(aObj.Spec.Replicas).To(Equal(tmp)) + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + kObj.Spec.Authorino = &kuadrantv1beta1.AuthorinoSpec{Replicas: ptr.To(int32(2))} + + Eventually(func() bool { + err := k8sClient.Update(ctx, kObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: common.AuthorinoName, Namespace: testNamespace}, aObj) + if err != nil { + return false + } + return reflect.DeepEqual(aObj.Spec.Replicas, ptr.To(int32(2))) + }).WithContext(ctx).Should(BeTrue()) + }) + + It("Kuadrant CR configuration should override Authorino CR configuration", func(ctx SpecContext) { + kObj := &kuadrantv1beta1.Kuadrant{} + aObj := &authorinov1beta1.Authorino{} + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: common.AuthorinoName, Namespace: testNamespace}, aObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + aObj.Spec.Replicas = ptr.To(int32(2)) + + Eventually(func() bool { + err := k8sClient.Update(ctx, aObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + kObj.Spec.Authorino = &kuadrantv1beta1.AuthorinoSpec{Replicas: ptr.To(int32(1))} + + Eventually(func() bool { + err := k8sClient.Update(ctx, kObj) + return err == nil + }).WithContext(ctx).Should(BeTrue()) + + Eventually(func() bool { + err := k8sClient.Get(ctx, client.ObjectKey{Name: common.AuthorinoName, Namespace: testNamespace}, aObj) + if err != nil { + return false + } + return reflect.DeepEqual(aObj.Spec.Replicas, ptr.To(int32(1))) + }).WithContext(ctx).Should(BeTrue()) + }) + }) +})