Skip to content

Commit

Permalink
Merge pull request #3 from mbaldessari/tests
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
mbaldessari authored Sep 25, 2024
2 parents 465ab5c + 9275b2a commit cc62382
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 3 deletions.
29 changes: 26 additions & 3 deletions tests/golang_external_secrets_default_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ templates:
release:
name: release-test
tests:
- it: Should output default values
- it: Should output default values for the secret
asserts:
- hasDocuments:
count: 2
- containsDocument:
kind: Secret
apiVersion: v1
name: golang-external-secrets
namespace: golang-external-secrets
documentSelector:
path: kind
value: Secret
- equal:
path: metadata.annotations["kubernetes.io/service-account.name"]
value: golang-external-secrets
documentSelector:
path: kind
value: Secret

- it: Should output default values for the clusterrolebinding
asserts:
- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: role-tokenreview-binding
namespace: golang-external-secrets
documentSelector:
path: kind
value: ClusterRoleBinding
151 changes: 151 additions & 0 deletions tests/golang_external_secrets_secretstore_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
suite: Test golang-external-secrets cluster secret store
templates:
- templates/vault/golang-external-secrets-hub-secretstore.yaml
release:
name: release-test
tests:
- it: should output nothing if .Value.global.secretStore is not "vault"
set:
global:
secretStore:
backend: "kubernetes"
asserts:
- hasDocuments:
count: 0

- it: should output things if the backend is not set (we assume vault as a default)
set:
global:
secretStore:
backend: null
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: ClusterSecretStore
apiVersion: external-secrets.io/v1beta1
name: vault-backend
namespace: golang-external-secrets

- it: should output things if the backend is set to vault
set:
global:
secretStore:
backend: "vault"
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: ClusterSecretStore
apiVersion: external-secrets.io/v1beta1
name: vault-backend
namespace: golang-external-secrets

- it: should set the vault server to the hubClusterDomain
set:
global:
hubClusterDomain: foo.bar.baz
asserts:
- equal:
path: spec.provider.vault.server
value: "https://vault-vault.foo.bar.baz"

- it: should set secretRef
asserts:
- equal:
path: spec.provider.vault.auth.kubernetes.secretRef.name
value: golang-external-secrets
- equal:
path: spec.provider.vault.auth.kubernetes.secretRef.namespace
value: golang-external-secrets
- equal:
path: spec.provider.vault.auth.kubernetes.secretRef.key
value: token

- it: should not set the caProvider when disabled
set:
golangExternalSecrets:
caProvider:
enabled: false
asserts:
- notExists:
path: spec.provider.vault.caProvider

- it: should set the caProvider to the hostCluster when on the hub
set:
clusterGroup:
isHubCluster: true
golangExternalSecrets:
caProvider:
hostCluster:
name: foo-bar-configmap
key: foo-key
namespace: foo
asserts:
- equal:
path: spec.provider.vault.caProvider.type
value: ConfigMap
- equal:
path: spec.provider.vault.caProvider.name
value: foo-bar-configmap
- equal:
path: spec.provider.vault.caProvider.key
value: foo-key
- equal:
path: spec.provider.vault.caProvider.namespace
value: foo

- it: should set the caProvider to the clientCluster when not on the hub
set:
clusterGroup:
isHubCluster: false
golangExternalSecrets:
caProvider:
clientCluster:
name: foo-bar-configmap
key: foo-key
namespace: foo
asserts:
- equal:
path: spec.provider.vault.caProvider.type
value: Secret
- equal:
path: spec.provider.vault.caProvider.name
value: foo-bar-configmap
- equal:
path: spec.provider.vault.caProvider.key
value: foo-key
- equal:
path: spec.provider.vault.caProvider.namespace
value: foo

- it: should set the kubernetes auth when on the hub
set:
clusterGroup:
isHubCluster: true
golangExternalSecrets:
rbac:
rolename: "hub-rolename"
vault:
mountPath: "hub-mount"
asserts:
- equal:
path: spec.provider.vault.auth.kubernetes.mountPath
value: hub-mount
- equal:
path: spec.provider.vault.auth.kubernetes.role
value: hub-rolename

- it: should set the kubernetes auth when not on the hub
set:
global:
clusterDomain: foo.bar
clusterGroup:
isHubCluster: false
asserts:
- equal:
path: spec.provider.vault.auth.kubernetes.mountPath
value: foo.bar
- equal:
path: spec.provider.vault.auth.kubernetes.role
value: foo.bar-role

0 comments on commit cc62382

Please sign in to comment.