Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redis replication integration tests #754

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions controllers/rediscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ var _ = Describe("Redis cluster test", func() {
redisClusterCR redisv1beta2.RedisCluster
redisClusterCRName string
size int32
// version string
// Used to create unique name for each test
testCount int
)

JustBeforeEach(func() {
size = 3
// version = "v7"
redisClusterCR = redisv1beta2.RedisCluster{
TypeMeta: metav1.TypeMeta{
APIVersion: "redis.redis.opstreelabs.in/v1beta2",
Expand All @@ -39,8 +37,7 @@ var _ = Describe("Redis cluster test", func() {
Namespace: ns,
},
Spec: redisv1beta2.RedisClusterSpec{
Size: &size,
// ClusterVersion: &version,
Size: &size,
Storage: &redisv1beta2.ClusterStorage{},
},
}
Expand All @@ -54,7 +51,6 @@ var _ = Describe("Redis cluster test", func() {

Context("When creating a redis cluster CR", func() {
It("should create a statefulset", func() {

sts := &appsv1.StatefulSet{}
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{
Expand Down
134 changes: 134 additions & 0 deletions controllers/redisreplication_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package controllers

import (
"context"
"fmt"

redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

var _ = Describe("Redis replication test", func() {
var (
redisReplicationCR redisv1beta2.RedisReplication
redisReplicationCRName string
size int32
// Used to create unique name for each test
testCount int
)

JustBeforeEach(func() {
size = 3
redisReplicationCR = redisv1beta2.RedisReplication{
TypeMeta: metav1.TypeMeta{
APIVersion: "redis.redis.opstreelabs.in/v1beta2",
Kind: "RedisReplication",
},
ObjectMeta: metav1.ObjectMeta{
Name: redisReplicationCRName,
Namespace: ns,
},
Spec: redisv1beta2.RedisReplicationSpec{
Size: &size,
Storage: &redisv1beta2.Storage{},
},
}
Expect(k8sClient.Create(context.TODO(), &redisReplicationCR)).Should(Succeed())
testCount++
})

BeforeEach(func() {
redisReplicationCRName = fmt.Sprintf("redis-replication-%d", testCount)
})

Context("When creating a redis replication CR", func() {
It("should create a statefulset", func() {

sts := &appsv1.StatefulSet{}
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{
Name: redisReplicationCRName,
Namespace: ns,
}, sts)
}, timeout, interval).Should(BeNil())

Expect(*sts.Spec.Replicas).To(BeEquivalentTo(3))
Expect(sts.Spec.ServiceName).To(Equal(redisReplicationCRName + "-headless"))
})

It("should create a service", func() {
svc := &corev1.Service{}
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{
Name: redisReplicationCRName,
Namespace: ns,
}, svc)
}, timeout, interval).Should(BeNil())

Expect(svc.Labels).To(Equal(map[string]string{
"app": redisReplicationCRName,
"redis_setup_type": "replication",
"role": "replication",
}))
})

It("should create a headless service", func() {
svc := &corev1.Service{}
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{
Name: redisReplicationCRName + "-headless",
Namespace: ns,
}, svc)
}, timeout, interval).Should(BeNil())

Expect(svc.Labels).To(Equal(map[string]string{
"app": redisReplicationCRName,
"redis_setup_type": "replication",
"role": "replication",
}))
})

It("should create additional service", func() {
svc := &corev1.Service{}
Eventually(func() error {
return k8sClient.Get(context.TODO(), types.NamespacedName{
Name: redisReplicationCRName + "-additional",
Namespace: ns,
}, svc)
}, timeout, interval).Should(BeNil())

Expect(svc.Labels).To(Equal(map[string]string{
"app": redisReplicationCRName,
"redis_setup_type": "replication",
"role": "replication",
}))
})

Context("then deleting the redis replication CR", func() {
It("should delete the statefulset", func() {
redisReplicationCR := &redisv1beta2.RedisReplication{
ObjectMeta: metav1.ObjectMeta{
Name: redisReplicationCRName,
Namespace: ns,
},
}
Expect(k8sClient.Delete(context.TODO(), redisReplicationCR)).To(BeNil())

Eventually(func() bool {
sts := &appsv1.StatefulSet{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{
Name: redisReplicationCRName,
Namespace: ns,
}, sts)
return errors.IsNotFound(err)
}, timeout, interval).Should(BeTrue())
})
})
})
})
8 changes: 8 additions & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ var _ = BeforeSuite(func() {
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

err = (&RedisReplicationReconciler{
Client: k8sManager.GetClient(),
K8sClient: k8sClient,
Dk8sClient: dk8sClient,
Scheme: k8sManager.GetScheme(),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

go func() {
defer GinkgoRecover()
err = k8sManager.Start(ctrl.SetupSignalHandler())
Expand Down
Loading