-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for redis standalone
Signed-off-by: Mathieu Cesbron <[email protected]>
- Loading branch information
1 parent
7665d4a
commit 0935e54
Showing
7 changed files
with
274 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
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" | ||
) | ||
|
||
const ( | ||
ns = "default" | ||
|
||
timeout = time.Second * 5 | ||
interval = time.Millisecond * 250 | ||
) | ||
|
||
var _ = Describe("Redis standalone test", func() { | ||
var ( | ||
redisCR redisv1beta2.Redis | ||
redisCRName string | ||
// Used to create unique name for each test | ||
testCount int | ||
) | ||
|
||
JustBeforeEach(func() { | ||
redisCR = redisv1beta2.Redis{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "redisv1beta2/apiVersion", | ||
Kind: "Redis", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: redisCRName, | ||
Namespace: ns, | ||
}, | ||
} | ||
Expect(k8sClient.Create(context.TODO(), &redisCR)).Should(Succeed()) | ||
testCount++ | ||
}) | ||
|
||
BeforeEach(func() { | ||
redisCRName = fmt.Sprintf("redis-%d", testCount) | ||
}) | ||
|
||
Context("When creating a redis standalone CR", func() { | ||
It("should create a statefulset", func() { | ||
var sts *appsv1.StatefulSet | ||
Eventually(func() error { | ||
sts = &appsv1.StatefulSet{} | ||
return k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Name: redisCRName, | ||
Namespace: ns, | ||
}, sts) | ||
}, timeout, interval).Should(BeNil()) | ||
|
||
Expect(sts.Labels).To(Equal(map[string]string{ | ||
"app": redisCRName, | ||
"redis_setup_type": "standalone", | ||
"role": "standalone", | ||
})) | ||
|
||
Expect(*sts.Spec.Replicas).To(BeEquivalentTo(1)) | ||
Expect(sts.Spec.ServiceName).To(Equal(redisCRName + "-headless")) | ||
}) | ||
|
||
It("should create a service", func() { | ||
var svc *corev1.Service | ||
Eventually(func() error { | ||
svc = &corev1.Service{} | ||
return k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Name: redisCR.Name, | ||
Namespace: ns, | ||
}, svc) | ||
}, timeout, interval).Should(BeNil()) | ||
|
||
Expect(svc.Labels).To(Equal(map[string]string{ | ||
"app": redisCRName, | ||
"redis_setup_type": "standalone", | ||
"role": "standalone", | ||
})) | ||
}) | ||
|
||
It("should create a headless service", func() { | ||
var svc *corev1.Service | ||
Eventually(func() error { | ||
svc = &corev1.Service{} | ||
return k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Name: redisCR.Name + "-headless", | ||
Namespace: ns, | ||
}, svc) | ||
}, timeout, interval).Should(BeNil()) | ||
|
||
Expect(svc.Labels).To(Equal(map[string]string{ | ||
"app": redisCRName, | ||
"redis_setup_type": "standalone", | ||
"role": "standalone", | ||
})) | ||
}) | ||
|
||
It("should create additional service", func() { | ||
var svc *corev1.Service | ||
Eventually(func() error { | ||
svc = &corev1.Service{} | ||
return k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Name: redisCR.Name + "-additional", | ||
Namespace: ns, | ||
}, svc) | ||
}, timeout, interval).Should(BeNil()) | ||
|
||
Expect(svc.Labels).To(Equal(map[string]string{ | ||
"app": redisCRName, | ||
"redis_setup_type": "standalone", | ||
"role": "standalone", | ||
})) | ||
}) | ||
|
||
Context("then deleting the redis standalone CR", func() { | ||
It("should delete the statefulset", func() { | ||
redisCR := &redisv1beta2.Redis{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: redisCRName, | ||
Namespace: ns, | ||
}, | ||
} | ||
Expect(k8sClient.Delete(context.TODO(), redisCR)).To(BeNil()) | ||
|
||
Eventually(func() bool { | ||
sts := &appsv1.StatefulSet{} | ||
err := k8sClient.Get(context.TODO(), types.NamespacedName{ | ||
Name: redisCRName, | ||
Namespace: ns, | ||
}, sts) | ||
return errors.IsNotFound(err) | ||
}, timeout, interval).Should(BeTrue()) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.