Skip to content

Commit

Permalink
Add integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Boomatang committed May 1, 2024
1 parent 105778d commit 77926e7
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions controllers/kuadrant_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//go:build integration

Check failure on line 1 in controllers/kuadrant_controller_test.go

View workflow job for this annotation

GitHub Actions / Auto-format and Check (goimports)

Please run goimports . diff --git a/controllers/kuadrant_controller_test.go b/controllers/kuadrant_controller_test.go index c92a5dc..026155c 100644 --- a/controllers/kuadrant_controller_test.go +++ b/controllers/kuadrant_controller_test.go @@ -3,15 +3,16 @@ package controllers import ( + "reflect" + "time" + 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() {

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())
})
})
})

0 comments on commit 77926e7

Please sign in to comment.