From bb4cec4c82b659dd78948945b1d02fc4444b026f Mon Sep 17 00:00:00 2001 From: drivebyer Date: Thu, 8 Feb 2024 18:25:24 +0800 Subject: [PATCH] test: remove redundant running spec Signed-off-by: drivebyer --- controllers/redis_controller_test.go | 20 ++++--------------- controllers/rediscluster_controller_test.go | 14 +++---------- .../redisreplication_controller_test.go | 14 ++++--------- controllers/redissentinel_controller_test.go | 13 +++--------- 4 files changed, 14 insertions(+), 47 deletions(-) diff --git a/controllers/redis_controller_test.go b/controllers/redis_controller_test.go index dbc90cffc..17830fd1f 100644 --- a/controllers/redis_controller_test.go +++ b/controllers/redis_controller_test.go @@ -44,10 +44,11 @@ var _ = Describe("Redis standalone test", func() { }) Context("When creating a redis standalone CR", func() { - It("should create a statefulset", func() { - var sts *appsv1.StatefulSet + It("should create a statefulset, service", func() { + sts := &appsv1.StatefulSet{} + svc := &corev1.Service{} + Eventually(func() error { - sts = &appsv1.StatefulSet{} return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisCRName, Namespace: ns, @@ -62,12 +63,8 @@ var _ = Describe("Redis standalone test", func() { 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, @@ -79,12 +76,8 @@ var _ = Describe("Redis standalone test", func() { "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, @@ -96,12 +89,7 @@ var _ = Describe("Redis standalone test", func() { "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, diff --git a/controllers/rediscluster_controller_test.go b/controllers/rediscluster_controller_test.go index da9933f07..6ae21cbd9 100644 --- a/controllers/rediscluster_controller_test.go +++ b/controllers/rediscluster_controller_test.go @@ -50,8 +50,10 @@ var _ = Describe("Redis cluster test", func() { }) Context("When creating a redis cluster CR", func() { - It("should create a statefulset", func() { + It("should create a statefulset, service", func() { sts := &appsv1.StatefulSet{} + svc := &corev1.Service{} + Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisClusterCRName + "-leader", @@ -67,10 +69,7 @@ var _ = Describe("Redis cluster test", func() { Expect(*sts.Spec.Replicas).To(BeEquivalentTo(3)) Expect(sts.Spec.ServiceName).To(Equal(redisClusterCRName + "-leader-headless")) - }) - It("should create a service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisClusterCRName + "-leader", @@ -83,10 +82,7 @@ var _ = Describe("Redis cluster test", func() { "redis_setup_type": "cluster", "role": "leader", })) - }) - It("should create a headless service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisClusterCRName + "-leader-headless", @@ -99,10 +95,6 @@ var _ = Describe("Redis cluster test", func() { "redis_setup_type": "cluster", "role": "leader", })) - }) - - It("should create additional service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisClusterCRName + "-leader-additional", diff --git a/controllers/redisreplication_controller_test.go b/controllers/redisreplication_controller_test.go index e7aee304b..3d12c07ee 100644 --- a/controllers/redisreplication_controller_test.go +++ b/controllers/redisreplication_controller_test.go @@ -48,9 +48,11 @@ var _ = Describe("Redis replication test", func() { }) Context("When creating a redis replication CR", func() { - It("should create a statefulset", func() { + It("should create a statefulset, service", func() { + svc := &corev1.Service{} sts := &appsv1.StatefulSet{} + Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisReplicationCRName, @@ -60,10 +62,7 @@ var _ = Describe("Redis replication test", func() { 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, @@ -76,10 +75,7 @@ var _ = Describe("Redis replication test", func() { "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", @@ -92,10 +88,7 @@ var _ = Describe("Redis replication test", func() { "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", @@ -108,6 +101,7 @@ var _ = Describe("Redis replication test", func() { "redis_setup_type": "replication", "role": "replication", })) + }) Context("then deleting the redis replication CR", func() { diff --git a/controllers/redissentinel_controller_test.go b/controllers/redissentinel_controller_test.go index 6b82ef460..a43a6b6f5 100644 --- a/controllers/redissentinel_controller_test.go +++ b/controllers/redissentinel_controller_test.go @@ -47,8 +47,10 @@ var _ = Describe("Redis sentinel test", func() { }) Context("When creating a redis sentinel CR", func() { - It("should create a statefulset", func() { + It("should create a statefulset, service", func() { sts := &appsv1.StatefulSet{} + svc := &corev1.Service{} + Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisSentinelCRName + "-sentinel", @@ -58,10 +60,7 @@ var _ = Describe("Redis sentinel test", func() { Expect(*sts.Spec.Replicas).To(BeEquivalentTo(3)) Expect(sts.Spec.ServiceName).To(Equal(redisSentinelCRName + "-sentinel-headless")) - }) - It("should create a service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisSentinelCRName + "-sentinel", @@ -74,10 +73,7 @@ var _ = Describe("Redis sentinel test", func() { "redis_setup_type": "sentinel", "role": "sentinel", })) - }) - It("should create a headless service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisSentinelCRName + "-sentinel-headless", @@ -90,10 +86,7 @@ var _ = Describe("Redis sentinel test", func() { "redis_setup_type": "sentinel", "role": "sentinel", })) - }) - It("should create additional service", func() { - svc := &corev1.Service{} Eventually(func() error { return k8sClient.Get(context.TODO(), types.NamespacedName{ Name: redisSentinelCRName + "-sentinel-additional",