Skip to content

Commit

Permalink
Merge pull request #132 from bdalpe/bug/131-fix-unittests
Browse files Browse the repository at this point in the history
Fix Helm Unit Tests
  • Loading branch information
bdalpe authored Apr 13, 2023
2 parents 156dc96 + b164f13 commit 49d08bf
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: 3.9.4
version: 3.11.3

- name: Install unittest plugin
run: helm plugin install https://github.com/quintush/helm-unittest
run: helm plugin install https://github.com/helm-unittest/helm-unittest --version 0.3.1

- name: helm lint
run: helm lint helm-chart-sources/*

- name: helm unittest
run: helm unittest -3 helm-chart-sources/*
run: helm unittest helm-chart-sources/*
12 changes: 8 additions & 4 deletions helm-chart-sources/edge/templates/common/_extras.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- define "common.extras" }}
{{ range .Values.extraObjects }}
{{- define "common.extras" -}}
{{- range .Values.extraObjects }}
---
{{ tpl (toYaml .) $ }}
{{ end }}
{{- if typeIs "string" . }}
{{ . | nindent 0 }}
{{- else }}
{{- toYaml . | nindent 0 }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 2 additions & 0 deletions helm-chart-sources/edge/templates/networking/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ spec:
{{- include "common.selectorLabels" . | nindent 4 }}
{{- if (and (not (empty .Values.service.loadBalancerIP)) (eq $.Values.service.type "LoadBalancer")) }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{- end }}
{{- if .Values.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions helm-chart-sources/edge/tests/daemonset_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
suite: DaemonSet
templates:
- daemonset.yaml
values:
- ./values/leader.yaml
tests:
- it: Creates a DaemonSet
asserts:
Expand Down
52 changes: 52 additions & 0 deletions helm-chart-sources/edge/tests/extras_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
suite: Extras
templates:
- extras.yaml
values:
- ./values/leader.yaml
tests:
- it: Creates something extra
template: extras.yaml

set:
extraObjects:
- |
kind: Foo
fake2: true
apiVersion: cribl.io/v1
asserts:
- hasDocuments:
count: 1
- equal:
path: kind
value: Foo
- equal:
path: fake2
value: true
- isAPIVersion:
of: cribl.io/v1

- it: Creates from object
template: extras.yaml
set:
extraObjects:
- apiVersion: v1
kind: Pod
- apiVersion: v1
kind: Secret
metadata:
name: foo
fake: 1234
asserts:
- hasDocuments:
count: 2
- containsDocument:
apiVersion: v1
kind: Pod
- equal:
path: metadata.name
value: foo
documentIndex: 1
- equal:
path: fake
value: 1234
documentIndex: 1
2 changes: 2 additions & 0 deletions helm-chart-sources/edge/tests/ingress_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
suite: Ingress
templates:
- networking/ingress.yaml
values:
- ./values/leader.yaml
tests:
- it: Doesn't create an Ingress by default
asserts:
Expand Down
2 changes: 2 additions & 0 deletions helm-chart-sources/edge/tests/rbac_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ suite: RBAC
templates:
- rbac/serviceaccount.yaml
- rbac/clusterrole.yaml
values:
- ./values/leader.yaml
tests:
- it: Creates a ServiceAccount
template: rbac/serviceaccount.yaml
Expand Down
7 changes: 7 additions & 0 deletions helm-chart-sources/edge/tests/secret_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ tests:
- equal:
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
value: sup3rsecr3t

# temp disable while this is fixed https://github.com/helm-unittest/helm-unittest/issues/133
# - it: Fails if not set
# template: daemonset.yaml
# asserts:
# - failedTemplate:
# errorMessage: A valid CRIBL_DIST_MASTER_URL is required to be defined in the cribl.leader value!
6 changes: 4 additions & 2 deletions helm-chart-sources/edge/tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
suite: Service
templates:
- networking/service.yaml
values:
- ./values/leader.yaml
tests:
- it: Doesn't create a Service by default
asserts:
Expand Down Expand Up @@ -63,7 +65,7 @@ tests:
enable: true
type: ClusterIP # redundant
loadBalancerIP: 1.2.3.4
assert:
asserts:
- isNull:
path: spec.loadBalancerIP

Expand All @@ -72,7 +74,7 @@ tests:
service:
enable: true
externalTrafficPolicy: Local
assert:
asserts:
- equal:
path: spec.externalTrafficPolicy
value: Local
16 changes: 16 additions & 0 deletions helm-chart-sources/edge/tests/values/leader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cribl:
leader: "for-UTs"

extraObjects:
- apiVersion: v1
kind: foo
- apiVersion: v1
kind: foo
extra:
test:
deep:
value: 1
- |
apiVersion: v1
foo: 1
asdf: asdfas

0 comments on commit 49d08bf

Please sign in to comment.