From 7187f41ef17cef50582a3ce88069389edfc666a6 Mon Sep 17 00:00:00 2001 From: Volodymyr Zotov Date: Thu, 21 Aug 2025 10:17:19 -0500 Subject: [PATCH] Checking that all secrets are created before running tests --- test/e2e/e2e_test.go | 30 +++++++++++++++++++++--------- test/testhelper/kube/kube.go | 11 +++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 13ae96a..bb89cf8 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -26,15 +26,30 @@ var _ = Describe("Onepassword Operator e2e", Ordered, func() { operator.BuildOperatorImage() kind.LoadImageToKind(operatorImageName) - By("Create Connect credentials secret") + By("Create Connect 'op-credentials' credentials secret") kube.CreateOpCredentialsSecret() - By("Create onepassword-token secret") + By("Checking Connect 'op-credentials' secret is created") + Eventually(func() { + kube.CheckSecretExists("op-credentials") + }, defaultTimeout, defaultInterval).Should(Succeed()) + + By("Create 'onepassword-token' secret") kube.CreateSecretFromEnvVar("OP_CONNECT_TOKEN", "onepassword-token") - By("Create onepassword-service-account-token secret") + By("Checking 'onepassword-token' secret is created") + Eventually(func() { + kube.CheckSecretExists("onepassword-token") + }, defaultTimeout, defaultInterval).Should(Succeed()) + + By("Create 'onepassword-service-account-token' secret") kube.CreateSecretFromEnvVar("OP_SERVICE_ACCOUNT_TOKEN", "onepassword-service-account-token") + By("Checking 'onepassword-service-account-token' secret is created") + Eventually(func() { + kube.CheckSecretExists("onepassword-service-account-token") + }, defaultTimeout, defaultInterval).Should(Succeed()) + operator.DeployOperator() operator.WaitingForOperatorPod() }) @@ -64,14 +79,11 @@ func runCommonTestCases() { Expect(err).NotTo(HaveOccurred()) yamlPath := filepath.Join(root, "test", "e2e", "manifests", "secret.yaml") - _, err = system.Run("kubectl", "apply", "-f", yamlPath) - Expect(err).NotTo(HaveOccurred()) + kube.Apply(yamlPath) By("Waiting for secret to be created") - Eventually(func(g Gomega) { - output, err := system.Run("kubectl", "get", "secret", "login", "-o", "jsonpath={.metadata.name}") - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(Equal("login")) + Eventually(func() { + kube.CheckSecretExists("login") }, defaultTimeout, defaultInterval).Should(Succeed()) }) } diff --git a/test/testhelper/kube/kube.go b/test/testhelper/kube/kube.go index 9f9ac78..5ebcc99 100644 --- a/test/testhelper/kube/kube.go +++ b/test/testhelper/kube/kube.go @@ -48,6 +48,17 @@ func DeleteSecret(name string) { Expect(err).NotTo(HaveOccurred()) } +func CheckSecretExists(name string) { + output, err := system.Run("kubectl", "get", "secret", name, "-o", "jsonpath={.metadata.name}") + Expect(err).NotTo(HaveOccurred()) + Expect(output).To(Equal(name)) +} + +func Apply(yamlPath string) { + _, err := system.Run("kubectl", "apply", "-f", yamlPath) + Expect(err).NotTo(HaveOccurred()) +} + func SetContextNamespace(namespace string) { By("Set namespace to " + namespace) _, err := system.Run("kubectl", "config", "set-context", "--current", "--namespace="+namespace)