Skip to content

Commit

Permalink
test: implement Helm chart unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcollom committed Oct 10, 2023
1 parent bee8f9b commit d96a0fe
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/helm-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Run Tests
run: |
if [ ! -e "deploy/charts/verson-checker/tests" ]; then
echo "Not running tests, directory doesn't exist: deploy/charts/verson-checker/tests"
if [ ! -e "deploy/charts/version-checker/tests" ]; then
echo "Not running tests, directory doesn't exist: deploy/charts/version-checker/tests"
exit 0
fi
helm unittest --helm3 --color deploy/charts/verson-checker
13 changes: 0 additions & 13 deletions deploy/charts/version-checker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,3 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Required claims serialized to CLI argument
*/}}
{{- define "requiredClaims" -}}
{{- if .Values.oidc.requiredClaims -}}
{{- $local := (list) -}}
{{- range $k, $v := .Values.oidc.requiredClaims -}}
{{- $local = (printf "%s=%s" $k $v | append $local) -}}
{{- end -}}
{{ join "," $local }}
{{- end -}}
{{- end -}}
3 changes: 2 additions & 1 deletion deploy/charts/version-checker/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kind: Deployment
metadata:
name: {{ $chartname }}
labels:
{{ include "version-checker.labels" . | indent 4 }}
{{ include "version-checker.labels" . | nindent 2 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
Expand All @@ -18,6 +18,7 @@ spec:
metadata:
labels:
app: {{ $chartname }}
{{ include "version-checker.labels" . | nindent 8 }}
annotations:
prometheus.io/path: "/metrics"
prometheus.io/scrape: "true"
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/version-checker/templates/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ metadata:
name: {{ include "version-checker.name" . }}
labels:
prometheus: {{ include "version-checker.name" . }}
{{ include "version-checker.labels" . | indent 4 }}
{{ include "version-checker.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.prometheus.replicas }}
serviceAccountName: {{ .Values.prometheus.serviceAccountName }}
Expand Down
308 changes: 308 additions & 0 deletions deploy/charts/version-checker/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
suite: test deployment
templates:
- deployment.yaml
tests:
- it: should work (defaults)
set:
image.tag: latest
asserts:
- isKind:
of: Deployment
- equal:
path: metadata.name
value: version-checker
- equal:
path: spec.template.spec.containers[0].image
value: quay.io/jetstack/version-checker:latest
- equal:
path: spec.template.spec.containers[0].resources
value: {}
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/name"]
value: version-checker
- equal:
path: spec.template.metadata.labels["app.kubernetes.io/instance"]
value: RELEASE-NAME
- equal:
path: spec.template.spec.containers[0].name
value: version-checker
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
- equal:
path: spec.template.spec.containers[0].readinessProbe
value:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
- isNullOrEmpty:
path: spec.template.spec.volumes

# ACR
- it: ACR should work
set:
acr.refreshToken: ajbhvdsbjvh
acr.username: jsgbjkas
acr.password: sgkjnabskjga
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ACR_REFRESH_TOKEN
valueFrom:
secretKeyRef:
key: acr.refreshToken
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ACR_USERNAME
valueFrom:
secretKeyRef:
key: acr.username
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ACR_PASSWORD
valueFrom:
secretKeyRef:
key: acr.password
name: version-checker

# ECR
- it: ECR should work
set:
ecr.iamRoleArn: ajbhvdsbjvh
ecr.accessKeyID: jsgbjkas
ecr.secretAccessKey: sgkjnabskjga
ecr.sessionToken: asgjasg
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ECR_IAM_ROLE_ARN
value: ajbhvdsbjvh
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ECR_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
key: ecr.accessKeyID
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ECR_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
key: ecr.secretAccessKey
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_ECR_SESSION_TOKEN
valueFrom:
secretKeyRef:
key: ecr.sessionToken
name: version-checker

# Docker
- it: Docker should work
set:
docker.token: ajbhvdsbjvh
docker.username: username
docker.password: hunter1
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_DOCKER_TOKEN
valueFrom:
secretKeyRef:
key: docker.token
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_DOCKER_USERNAME
valueFrom:
secretKeyRef:
key: docker.username
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_DOCKER_PASSWORD
valueFrom:
secretKeyRef:
key: docker.password
name: version-checker

# GCR
- it: GCR should work
set:
gcr.token: ajbhvdsbjvh
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_GCR_TOKEN
valueFrom:
secretKeyRef:
key: gcr.token
name: version-checker

# Quay
- it: Quay should work
set:
quay.token: ajbhvdsbjvh
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_QUAY_TOKEN
valueFrom:
secretKeyRef:
key: quay.token
name: version-checker

# Self Hosted
- it: Self hosted should work
set:
selfhosted:
- name: bob
host: http://example.com
username: asgasasf
password: hunter1
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_HOST_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.host
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_USERNAME_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.username
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_PASSWORD_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.password
name: version-checker
- notContains:
path: spec.template.spec.containers[0].env
content:
name: VERSION_CHECKER_SELFHOSTED_TOKEN_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.password
name: version-checker

# Multiple Self Hosted
- it: Multiple Self hosted should work
set:
selfhosted:
- name: bob
host: http://example.com
username: asgasasf
password: hunter1
- name: bill
host: http://sub.example.com
token: askjgnasbjkgas
asserts:
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_HOST_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.host
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_USERNAME_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.username
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
count: 1
content:
name: VERSION_CHECKER_SELFHOSTED_PASSWORD_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.password
name: version-checker
- notContains:
path: spec.template.spec.containers[0].env
content:
name: VERSION_CHECKER_SELFHOSTED_TOKEN_bob
valueFrom:
secretKeyRef:
key: selfhosted.bob.password
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
content:
name: VERSION_CHECKER_SELFHOSTED_TOKEN_bill
valueFrom:
secretKeyRef:
key: selfhosted.bill.token
name: version-checker
- contains:
path: spec.template.spec.containers[0].env
content:
name: VERSION_CHECKER_SELFHOSTED_HOST_bill
valueFrom:
secretKeyRef:
key: selfhosted.bill.host
name: version-checker

- it: SecretEnabled
set:
acr.refreshToken: asgasga
asserts:
- contains:
path: spec.template.spec.volumes
content:
name: version-checker
secret:
secretName: version-checker
Loading

0 comments on commit d96a0fe

Please sign in to comment.