Introducing unit tests for helm chart

Signed-off-by: Stavros Foteinopoulos <stafot@gmail.com>
This commit is contained in:
Stavros Foteinopoulos 2023-11-28 14:12:30 +02:00
parent 36abefd02f
commit 5eea7753b8
No known key found for this signature in database
GPG key ID: 7187B9E13C5E5E93
5 changed files with 61 additions and 1 deletions

View file

@ -163,6 +163,14 @@ jobs:
go-version: '1.21.3'
check-latest: true
- name: Install Helm Unit Test Plugin
run: |
helm plugin install https://github.com/quintush/helm-unittest
- name: Run Helm Unit Tests
run: |
helm unittest charts/ingress-nginx -d
- name: cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:

1
.gitignore vendored
View file

@ -61,3 +61,4 @@ cmd/plugin/release/*.tar.gz
cmd/plugin/release/LICENSE
tmp/
test/junitreports/
tests/__snapshot__

View file

@ -20,3 +20,4 @@
.idea/
*.tmproj
.vscode/
__snapshot__

View file

@ -1,10 +1,11 @@
{{- if .Values.defaultBackend.enabled }}
{{- range .Values.defaultBackend.extraConfigMaps }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .name }}
namespace: {{ include "ingress-nginx.namespace" . }}
namespace: {{ include "ingress-nginx.namespace" $ | quote }}
labels:
{{- include "ingress-nginx.labels" $ | nindent 4 }}
{{- with $.Values.defaultBackend.labels }}

View file

@ -0,0 +1,49 @@
suite: test default backend extra ConfigMaps
templates:
- default-backend-extra-configmaps.yaml
tests:
- it: should not create any ConfigMap by default
set:
Release.Namespace: default
defaultBackend.enabled: true
asserts:
- hasDocuments:
count: 0
- it: should create one ConfigMap
set:
Release.Namespace: default
defaultBackend.enabled: true
defaultBackend.extraConfigMaps:
- name: my-configmap-1
data:
key1: value1
asserts:
- hasDocuments:
count: 1
- isKind:
of: ConfigMap
- equal:
path: metadata.name
value: my-configmap-1
- it: should correctly render multiple ConfigMaps
set:
Release.Namespace: nginx
defaultBackend.enabled: true
defaultBackend.extraConfigMaps:
- name: my-configmap-1
data:
key1: value1
- name: my-configmap-2
data:
key2: value2
asserts:
- hasDocuments:
count: 2
- isKind:
of: ConfigMap
- matchRegex:
path: metadata.name
pattern: "my-configmap-\\d+"