Skip to content

Commit

Permalink
add chart tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarbian-sap committed Oct 15, 2023
1 parent e3a9af6 commit 6e57a9f
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
50 changes: 50 additions & 0 deletions chart/templates/tests/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "secret-generator.fullname" . }}-test
labels:
{{- include "secret-generator.labels" . | nindent 4 }}
annotations:
helm.sh/hook: test
helm.sh/hook-weight: "-1"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "secret-generator.fullname" . }}-test
labels:
{{- include "secret-generator.labels" . | nindent 4 }}
annotations:
helm.sh/hook: test
helm.sh/hook-weight: "-1"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "secret-generator.fullname" . }}-test
labels:
{{- include "secret-generator.labels" . | nindent 4 }}
annotations:
helm.sh/hook: test
helm.sh/hook-weight: "-1"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: {{ include "secret-generator.fullname" . }}-test
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "secret-generator.fullname" . }}-test
54 changes: 54 additions & 0 deletions chart/templates/tests/test-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- $secretName := printf "%s-test-1-%s" (include "secret-generator.fullname" .) (randAlphaNum 10 | lower) }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ $secretName }}
labels:
{{- include "secret-generator.labels" . | nindent 4 }}
annotations:
helm.sh/hook: test
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
labels:
secret-generator.cs.sap.com/enabled: "true"
stringData:
password: "%generate:password:length=50"
uuid: "%generate:uuid"
---
apiVersion: v1
kind: Pod
metadata:
name: {{ include "secret-generator.fullname" . }}-test-1
labels:
{{- include "secret-generator.labels" . | nindent 4 }}
annotations:
helm.sh/hook: test
helm.sh/hook-weight: "1"
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
containers:
- name: kubectl
image: bitnami/kubectl:{{ .Capabilities.KubeVersion.Version | trimPrefix "v" }}
command:
- bash
- -e
- -o
- pipefail
- -c
- |
password=$(kubectl get secret {{ $secretName }} -o jsonpath='{.data.password}' | base64 -d)
echo "got password: $password"
if [ ${#password} -ne 50 ]; then
echo "unexpected password length: ${#password}"
exit 1
fi
uuid=$(kubectl get secret {{ $secretName }} -o jsonpath='{.data.uuid}' | base64 -d)
echo "got uuid: $uuid"
if [ ${#uuid} -ne 36 ]; then
echo "unexpected uuid length: ${#uuid}"
exit 1
fi
serviceAccountName: {{ include "secret-generator.fullname" . }}-test
terminationGracePeriodSeconds: 3
restartPolicy: Never

0 comments on commit 6e57a9f

Please sign in to comment.