Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
Add kuadrant CR configuration to limitador CR configuration
  • Loading branch information
Boomatang committed Jan 23, 2024
1 parent 624f58b commit 9a5cff5
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions controllers/kuadrant_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//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 a09b965..d6fb094 100644 --- a/controllers/kuadrant_controller_test.go +++ b/controllers/kuadrant_controller_test.go @@ -4,15 +4,16 @@ package controllers import ( "context" + "reflect" + "time" + kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1" "github.com/kuadrant/kuadrant-operator/pkg/common" "github.com/kuadrant/limitador-operator/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/utils/ptr" - "reflect" "sigs.k8s.io/controller-runtime/pkg/client" - "time" ) var _ = FDescribe("Kuadrant controller", func() {

package controllers

import (
"context"
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
"github.com/kuadrant/kuadrant-operator/pkg/common"
"github.com/kuadrant/limitador-operator/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/ptr"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"
)

var _ = FDescribe("Kuadrant controller", func() {
var (
testNamespace string
kuadrant = "kuadrant-sample"
)
Context("Reconcile limitador resources", func() {
BeforeEach(func() {
CreateNamespace(&testNamespace)
ApplyKuadrantCR(testNamespace)
})

AfterEach(DeleteNamespaceCallback(&testNamespace))
It("Copy configuration from Kuadrant CR to Limitador CR", func() {
kObj := &kuadrantv1beta1.Kuadrant{}
lObj := &v1alpha1.Limitador{}

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj)
return err == nil
}, time.Minute, 5*time.Second).Should(BeTrue())

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
return err == nil
}, time.Minute, 5*time.Second).Should(BeTrue())
var tmp *int
Expect(lObj.Spec.Replicas).Should(Equal(tmp))

kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(1)}
err := k8sClient.Update(context.Background(), kObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
if err != nil {
return false
}
if reflect.DeepEqual(lObj.Spec.Replicas, ptr.To(1)) {
return false
}
return true
}, time.Minute, 5*time.Second).Should(BeTrue())
})

It("Kuadrant CR configuration overrides Limitador CR configuration", func() {
kObj := &kuadrantv1beta1.Kuadrant{}
lObj := &v1alpha1.Limitador{}

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
return err == nil
}, time.Minute, 5*time.Second).Should(BeTrue())
lObj.Spec.Replicas = ptr.To(1)
err := k8sClient.Update(context.Background(), lObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: kuadrant, Namespace: testNamespace}, kObj)
return err == nil
}, time.Minute, 5*time.Second).Should(BeTrue())

kObj.Spec.Limitador = &kuadrantv1beta1.LimitadorSpec{Replicas: ptr.To(2)}
err = k8sClient.Update(context.Background(), kObj)
Expect(err).ToNot(HaveOccurred())

Eventually(func() bool {
err := k8sClient.Get(context.Background(), client.ObjectKey{Name: common.LimitadorName, Namespace: testNamespace}, lObj)
if err != nil {
return false
}
if reflect.DeepEqual(lObj.Spec.Replicas, ptr.To(2)) {
return false
}
return true
}, time.Minute, 5*time.Second).Should(BeTrue())
})
})
})

0 comments on commit 9a5cff5

Please sign in to comment.