Files
onepassword-operator/test/e2e/e2e_test.go
2025-08-21 09:56:37 -05:00

78 lines
2.1 KiB
Go

package e2e
import (
"path/filepath"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/1Password/onepassword-operator/test/testhelper/kind"
"github.com/1Password/onepassword-operator/test/testhelper/kube"
"github.com/1Password/onepassword-operator/test/testhelper/operator"
"github.com/1Password/onepassword-operator/test/testhelper/system"
)
const (
operatorImageName = "1password/onepassword-operator:latest"
defaultInterval = 1 * time.Second
defaultTimeout = 1 * time.Minute
)
var _ = Describe("Onepassword Operator e2e", Ordered, func() {
BeforeAll(func() {
kube.SetContextNamespace("default")
operator.BuildOperatorImage()
kind.LoadImageToKind(operatorImageName)
By("Create Connect credentials secret")
kube.CreateOpCredentialsSecret()
By("Create onepassword-token secret")
kube.CreateSecretFromEnvVar("OP_CONNECT_TOKEN", "onepassword-token")
By("Create onepassword-service-account-token secret")
kube.CreateSecretFromEnvVar("OP_SERVICE_ACCOUNT_TOKEN", "onepassword-service-account-token")
operator.DeployOperator()
operator.WaitingForOperatorPod()
})
Context("Use the operator with Connect", func() {
BeforeAll(func() {
operator.WaitingForConnectPod()
})
runCommonTestCases()
})
Context("Use the operator with Service Account", func() {
BeforeAll(func() {
kube.PatchOperatorToUseServiceAccount()
kube.DeleteSecret("login") // remove secret crated in previous test
})
runCommonTestCases()
})
})
func runCommonTestCases() {
It("Should create secret from manifest file", func() {
By("Creating secret")
root, err := system.GetProjectRoot()
Expect(err).NotTo(HaveOccurred())
yamlPath := filepath.Join(root, "test", "e2e", "manifests", "secret.yaml")
_, err = system.Run("kubectl", "apply", "-f", yamlPath)
Expect(err).NotTo(HaveOccurred())
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"))
}, defaultTimeout, defaultInterval).Should(Succeed())
})
}