Abstract
Unit tests for helm charts.
Unit Tests#
Usage#
Install the [helm unittest] plugin.
helm plugin install https://github.com/helm-unittest/helm-unittest
Run the tests.
helm unittest -f 'tests/*.yaml' .
Test Suites#
This provides the following suites.
Ingress Suite#
- suite
Ingress Test Suite
Tests to validate the deployment of the described Ingress.
suite: ingress templates: - templates/ingress.yaml release: name: monero values: - ../values.yaml set: ingress: annotations: {} className: nginx enabled: true externalIPs: [] hosts: - host: monero.example.com paths: - path: / pathType: Prefix port: 18080 loadBalancerIP: '' tls: - hosts: - monero.example.com secretName: monero-tls labels: node: k8s05.example.com
- tests
Ingress Tests
Tests for Ingress Template
tests: - it: Should create an Ingress named 'monero' with correct metadata asserts: - equal: path: metadata.name value: monero - equal: path: metadata.labels value: app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com - it: Should configure the correct ingressClassName asserts: - equal: path: spec.ingressClassName value: nginx - it: Should configure the correct TLS settings asserts: - equal: path: spec.tls[0].hosts[0] value: monero.example.com - equal: path: spec.tls[0].secretName value: monero-tls - it: Should configure the correct rules for the Ingress asserts: - equal: path: spec.rules[0].host value: monero.example.com - equal: path: spec.rules[0].http.paths[0].path value: / - equal: path: spec.rules[0].http.paths[0].pathType value: Prefix - equal: path: spec.rules[0].http.paths[0].backend.service.name value: monero - equal: path: spec.rules[0].http.paths[0].backend.service.port.number value: 18080
Secret Suite#
- suite
Secret Test Suite
Tests to validate the deployment of the described Secrets.
suite: secret templates: - templates/secret.yaml release: name: monero values: - ../values.yaml set: ingress: secret: enabled: true crt: bm90LWEtY2VydAo= key: bm90LWEta2V5Cg== labels: node: k8s05.example.com monero: login: enabled: true MONEROD_PASSWORD: bm90LWEtcGFzc3dvcmQK MONEROD_USERNAME: bm90LWEtdXNlcm5hbWUK
- tests
TLS Secret Tests
Tests for TLS Secret Template
tests: - it: Should create a TLS Secret named 'monero-tls' with correct metadata asserts: - equal: path: metadata.name value: monero-tls - equal: path: metadata.namespace value: monero - equal: path: metadata.labels value: app.kubernetes.io/component: tls app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com documentIndex: 0 - it: Should correctly encode the tls.crt and tls.key data asserts: - equal: path: data value: tls.crt: bm90LWEtY2VydAo= tls.key: bm90LWEta2V5Cg== documentIndex: 0 - it: Should create a Secret named 'monero-login' with correct metadata asserts: - equal: path: metadata.name value: monero-login - equal: path: metadata.namespace value: monero - equal: path: metadata.labels value: app.kubernetes.io/component: login app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com documentIndex: 1 - it: Should correctly encode the moneroUsername and moneroPassword data asserts: - equal: path: data value: MONEROD_PASSWORD: null MONEROD_USERNAME: null documentIndex: 1
Service Suite#
- suite
Service Test Suite
Tests to validate the deployment of the described Service.
suite: service templates: - templates/service.yaml release: name: monero values: - ../values.yaml set: labels: node: k8s05.example.com
- tests
Service Tests
Tests for Service Template
tests: - it: Should create a Service named 'monero' with correct metadata asserts: - equal: path: metadata.name value: monero - equal: path: metadata.labels value: app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com - it: Should have a LoadBalancer type and correct ports configuration asserts: - equal: path: spec.type value: LoadBalancer - equal: path: spec.ports value: - name: monero port: 18081 protocol: TCP targetPort: 18081 - it: Should have correct selectors for the service asserts: - equal: path: spec.selector value: app.kubernetes.io/name: monero app.kubernetes.io/instance: monero - it: Should have an empty externalIPs list and no loadBalancerIP asserts: - equal: path: spec.externalIPs value: [] - equal: path: spec.loadBalancerIP value: null
ServiceAccount Suite#
- suite
ServiceAccount Test Suite
Tests to validate the deployment of the described ServiceAccount.
suite: serviceaccount templates: - templates/serviceaccount.yaml release: name: monero values: - ../values.yaml set: labels: node: k8s05.example.com
- tests
ServiceAccount Tests
Tests for ServiceAccount Template
tests: - it: Should create a ServiceAccount named 'monero' with correct metadata asserts: - equal: path: metadata.name value: monero - equal: path: metadata.annotations value: app.kubernetes.io/instance: monero app.kubernetes.io/name: monero - equal: path: metadata.labels value: app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com - it: Should have automountServiceAccountToken set to true asserts: - equal: path: automountServiceAccountToken value: true
StatefulSet Suite#
- suite
StatefulSet Test Suite
Tests to validate the deployment of the described StatefulSet.
suite: statefulset templates: - templates/statefulset.yaml release: name: monero values: - ../values.yaml set: labels: node: k8s05.example.com
- tests
StatefulSet Tests
Tests for StatefulSet Template
tests: - it: Should create a StatefulSet named 'monero' with correct metadata asserts: - equal: path: metadata.name value: monero - equal: path: metadata.labels value: app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com - it: Should have correct selector and matchLabels asserts: - equal: path: spec.selector.matchLabels value: app.kubernetes.io/name: monero app.kubernetes.io/instance: monero - it: Should configure the Pod template metadata and labels correctly asserts: - equal: path: spec.template.metadata.labels value: app.kubernetes.io/instance: monero app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: monero app.kubernetes.io/node: k8s05.breeze-blocks.net app.kubernetes.io/version: 0.18.3.4-2 helm.sh/chart: monero-0.0.2 node: k8s05.example.com pod-security.kubernetes.io/enforce: privileged pod-security.kubernetes.io/enforce-version: latest - it: Should create the correct container configuration asserts: - equal: path: spec.template.spec.containers value: - image: edwardtheharris/monero-node:0.0.2 imagePullPolicy: Always name: monero ports: - containerPort: 18081 name: monero resources: limits: cpu: "3" memory: 6Gi requests: cpu: "2" memory: 4Gi volumeMounts: - mountPath: /srv/monero name: monero - equal: path: spec.template.spec.containers[0].ports value: - containerPort: 18081 name: monero - equal: path: spec.template.spec.containers[0].resources value: limits: cpu: "3" memory: 6Gi requests: cpu: "2" memory: 4Gi - equal: path: spec.template.spec.containers[0].volumeMounts[0].name value: monero - equal: path: spec.template.spec.containers[0].volumeMounts[0].mountPath value: /srv/monero - it: Should set serviceAccountName to 'monero' asserts: - equal: path: spec.template.spec.serviceAccountName value: monero - it: Should define volumeClaimTemplates with correct storage settings asserts: - equal: path: spec.volumeClaimTemplates[0].metadata.name value: monero - equal: path: spec.volumeClaimTemplates[0].spec.accessModes value: - ReadWriteOnce - ReadWriteMany - equal: path: spec.volumeClaimTemplates[0].spec.resources.requests.storage value: "300Gi" - equal: path: spec.volumeClaimTemplates[0].spec.storageClassName value: csi-lvm-linear - equal: path: spec.volumeClaimTemplates[0].spec.volumeMode value: Filesystem