diff --git a/test/kube/kube.go b/test/kube/kube.go deleted file mode 100644 index fa26c4b..0000000 --- a/test/kube/kube.go +++ /dev/null @@ -1,21 +0,0 @@ -package kube - -import ( - "os" - - . "github.com/onsi/gomega" - - "github.com/1Password/onepassword-operator/test/cmd" -) - -func CreateSecretFromEnvVar(envVar, secretName string) { - serviceAccountTokenToken, _ := os.LookupEnv(envVar) - Expect(serviceAccountTokenToken).NotTo(BeEmpty()) - _, err := cmd.Run("kubectl", "create", "secret", "generic", secretName, "--from-literal=token="+serviceAccountTokenToken) - Expect(err).NotTo(HaveOccurred()) -} - -func Delete(kind, name string) { - _, err := cmd.Run("kubectl", "delete", kind, name, "--ignore-not-found=true") - Expect(err).NotTo(HaveOccurred()) -} diff --git a/test/kind/kind.go b/test/testhelper/kind/kind.go similarity index 99% rename from test/kind/kind.go rename to test/testhelper/kind/kind.go index 55f382b..f3d3b48 100644 --- a/test/kind/kind.go +++ b/test/testhelper/kind/kind.go @@ -1,8 +1,9 @@ package kind import ( - "github.com/1Password/onepassword-operator/test/cmd" "os" + + "github.com/1Password/onepassword-operator/test/cmd" ) // LoadImageToKind loads a local docker image to the Kind cluster diff --git a/test/kube/deploy.go b/test/testhelper/kube/kube.go similarity index 61% rename from test/kube/deploy.go rename to test/testhelper/kube/kube.go index ed8e308..4579b86 100644 --- a/test/kube/deploy.go +++ b/test/testhelper/kube/kube.go @@ -1,6 +1,7 @@ package kube import ( + "os" "time" . "github.com/onsi/ginkgo/v2" @@ -9,31 +10,15 @@ import ( "github.com/1Password/onepassword-operator/test/cmd" ) -// DeployOperator deploys the Onepassword Operator in the default namespace. -// It waits for the operator pod to be in 'Running' state. -// All the resources created using manifests in `config/` dir. -// To make the operator use Connect or Service Accounts, patch `config/manager/manager.yaml` -func DeployOperator() { - By("deploying the operator") - _, err := cmd.Run("make", "deploy") +func CreateSecretFromEnvVar(envVar, secretName string) { + serviceAccountTokenToken, _ := os.LookupEnv(envVar) + Expect(serviceAccountTokenToken).NotTo(BeEmpty()) + _, err := cmd.Run("kubectl", "create", "secret", "generic", secretName, "--from-literal=token="+serviceAccountTokenToken) Expect(err).NotTo(HaveOccurred()) - - By("waiting for the operator pod to be 'Running'") - Eventually(func(g Gomega) { - output, err := cmd.Run("kubectl", "get", "pods", - "-l", "name=onepassword-connect-operator", - "-o", "jsonpath={.items[0].status.phase}") - g.Expect(err).NotTo(HaveOccurred()) - g.Expect(output).To(ContainSubstring("Running")) - }, 30*time.Second, 1*time.Second).Should(Succeed()) } -func UndeployOperator() { - Delete("secret", "onepassword-connect-token") - Delete("secret", "onepassword-service-account-token") - - By("undeploying the operator") - _, err := cmd.Run("make", "undeploy", "ignore-not-found") +func Delete(kind, name string) { + _, err := cmd.Run("kubectl", "delete", kind, name, "--ignore-not-found=true") Expect(err).NotTo(HaveOccurred()) } diff --git a/test/testhelper/operator/operator.go b/test/testhelper/operator/operator.go new file mode 100644 index 0000000..794efea --- /dev/null +++ b/test/testhelper/operator/operator.go @@ -0,0 +1,39 @@ +package operator + +import ( + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/1Password/onepassword-operator/test/cmd" + "github.com/1Password/onepassword-operator/test/testhelper/kube" +) + +// DeployOperator deploys the Onepassword Operator in the default namespace. +// It waits for the operator pod to be in 'Running' state. +// All the resources created using manifests in `config/` dir. +// To make the operator use Connect or Service Accounts, patch `config/manager/manager.yaml` +func DeployOperator() { + By("deploying the operator") + _, err := cmd.Run("make", "deploy") + Expect(err).NotTo(HaveOccurred()) + + By("waiting for the operator pod to be 'Running'") + Eventually(func(g Gomega) { + output, err := cmd.Run("kubectl", "get", "pods", + "-l", "name=onepassword-connect-operator", + "-o", "jsonpath={.items[0].status.phase}") + g.Expect(err).NotTo(HaveOccurred()) + 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()) +}