Browse Source

Fix a ClusterExternalSecret flaky test (#2641)

Signed-off-by: shuheiktgw <s-kitagawa@mercari.com>
Shuhei Kitagawa 2 years ago
parent
commit
ba1caed791

+ 12 - 6
pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller_test.go

@@ -368,17 +368,17 @@ var _ = Describe("ClusterExternalSecret controller", func() {
 			clusterExternalSecret: func(namespaces []v1.Namespace) esv1beta1.ClusterExternalSecret {
 				ces := defaultClusterExternalSecret()
 				ces.Spec.NamespaceSelector.MatchLabels = map[string]string{"kubernetes.io/metadata.name": namespaces[0].Name}
-				return *ces
-			},
-			beforeCheck: func(ctx context.Context, namespaces []v1.Namespace, created esv1beta1.ClusterExternalSecret) {
+
 				es := &esv1beta1.ExternalSecret{
 					ObjectMeta: metav1.ObjectMeta{
-						Name:      created.Name,
+						Name:      ces.Name,
 						Namespace: namespaces[0].Name,
 					},
 				}
-				Expect(k8sClient.Create(ctx, es)).ShouldNot(HaveOccurred())
-
+				Expect(k8sClient.Create(context.Background(), es)).ShouldNot(HaveOccurred())
+				return *ces
+			},
+			beforeCheck: func(ctx context.Context, namespaces []v1.Namespace, created esv1beta1.ClusterExternalSecret) {
 				ces := esv1beta1.ClusterExternalSecret{}
 				Eventually(func(g Gomega) {
 					key := types.NamespacedName{Namespace: created.Namespace, Name: created.Name}
@@ -386,6 +386,12 @@ var _ = Describe("ClusterExternalSecret controller", func() {
 					g.Expect(len(ces.Status.FailedNamespaces)).Should(Equal(1))
 				}).WithTimeout(timeout).WithPolling(interval).Should(Succeed())
 
+				es := &esv1beta1.ExternalSecret{
+					ObjectMeta: metav1.ObjectMeta{
+						Name:      ces.Name,
+						Namespace: namespaces[0].Name,
+					},
+				}
 				Expect(k8sClient.Delete(ctx, es)).ShouldNot(HaveOccurred())
 			},
 			expectedClusterExternalSecret: func(namespaces []v1.Namespace, created esv1beta1.ClusterExternalSecret) esv1beta1.ClusterExternalSecret {