From e167db2357131623903af2c055d7cb6188ac0e7e Mon Sep 17 00:00:00 2001 From: Volodymyr Zotov Date: Wed, 20 Aug 2025 10:28:18 -0500 Subject: [PATCH] Remove secret from previous step --- test/cmd/cmd.go | 24 ++++++++++++++++++++++++ test/e2e/e2e_test.go | 1 + test/testhelper/kube/kube.go | 4 ++-- test/testhelper/operator/operator.go | 10 ---------- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/test/cmd/cmd.go b/test/cmd/cmd.go index 8303934..ea3f9e9 100644 --- a/test/cmd/cmd.go +++ b/test/cmd/cmd.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "strings" ) @@ -27,3 +28,26 @@ func Run(name string, args ...string) (string, error) { return string(output), nil } + +func GetProjectRoot() (string, error) { + dir, err := os.Getwd() + if err != nil { + return "", err + } + + for { + // check if go.mod exists in current dir + modFile := filepath.Join(dir, "go.mod") + if _, err := os.Stat(modFile); err == nil { + return dir, nil + } + + // move one level up + parent := filepath.Dir(dir) + if parent == dir { + // reached filesystem root + return "", fmt.Errorf("project root not found (no go.mod)") + } + dir = parent + } +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 668bd76..ac69e82 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -48,6 +48,7 @@ var _ = Describe("Onepassword Operator e2e", Ordered, func() { Context("Use the operator with Service Account", func() { BeforeAll(func() { kube.PatchOperatorToUseServiceAccount() + kube.DeleteSecret("login") // remove secret crated in previous test }) runCommonTestCases() diff --git a/test/testhelper/kube/kube.go b/test/testhelper/kube/kube.go index e4d000f..bba018c 100644 --- a/test/testhelper/kube/kube.go +++ b/test/testhelper/kube/kube.go @@ -40,8 +40,8 @@ func CreateOpCredentialsSecret() { CreateSecretFromFile("op-session", "op-credentials") } -func Delete(kind, name string) { - _, err := cmd.Run("kubectl", "delete", kind, name, "--ignore-not-found=true") +func DeleteSecret(name string) { + _, err := cmd.Run("kubectl", "delete", "secret", name, "--ignore-not-found=true") Expect(err).NotTo(HaveOccurred()) } diff --git a/test/testhelper/operator/operator.go b/test/testhelper/operator/operator.go index c56f5e0..d368bf0 100644 --- a/test/testhelper/operator/operator.go +++ b/test/testhelper/operator/operator.go @@ -7,7 +7,6 @@ import ( . "github.com/onsi/gomega" "github.com/1Password/onepassword-operator/test/cmd" - "github.com/1Password/onepassword-operator/test/testhelper/kube" ) func BuildOperatorImage() { @@ -34,12 +33,3 @@ func DeployOperator() { g.Expect(output).To(ContainSubstring("Running")) }, 30*time.Second, 1*time.Second).Should(Succeed()) } - -func UndeployOperator() { - kube.Delete("secret", "onepassword-connect-token") - kube.Delete("secret", "onepassword-service-account-token") - - By("undeploying the operator") - _, err := cmd.Run("make", "undeploy", "ignore-not-found") - Expect(err).NotTo(HaveOccurred()) -}