40 / 75 · 08 Infrastructure as Code Testing · Helm Chart Testing← prev⊞ allnext →☰ Read as one page
7.6Integration Testing with chart-testing (ct)
chart-testing (ct) by Helm maintainers validates charts by actually installing them in a cluster. Use it with kind (Kubernetes in Docker) for CI:
# .github/workflows/helm-test.yml
name: Helm Chart Tests
on:
pull_request:
paths:
- 'charts/**'
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
- name: Set up chart-testing
uses: helm/chart-testing-action@v2
- name: Lint charts
run: ct lint --all
- name: Create kind cluster
uses: helm/kind-action@v1
- name: Install and test charts
run: ct install --all
In-Chart Test Hooks
Helm supports test hooks -- pods that run after installation to verify the chart works:
# templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "myapp.fullname" . }}-test-connection"
labels:
{{- include "myapp.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-delete-policy": hook-succeeded
spec:
containers:
- name: wget
image: busybox:1.36
command: ['wget']
args: ['{{ include "myapp.fullname" . }}:{{ .Values.service.port }}/healthz']
restartPolicy: Never
# Run chart tests after installation
helm test myapp --namespace production