Testing Charts
1. Running Chart Tests
| Command | Description | Options |
|---|---|---|
| helm test | Execute tests defined in a chart | --cleanup, --timeout, --namespace |
Note: Tests are defined in
templates/tests/ directory of the chart.
Warning: Ensure tests are idempotent and do not modify the release state.
2. Creating Test Pods
| Field | Description | Example |
|---|---|---|
| name | Unique identifier for the test pod | my-app-test |
| image | Docker image to run in the pod | nginx:1.21 |
| command | Command to execute inside the container | ["/bin/sh", "-c", "echo 'test passed'"] |
| resources | Resource limits and requests for the pod | {"limits": {"memory": "64Mi", "cpu": "250m"}} |
Example: Basic Test Pod Configuration
apiVersion: v1
kind: Pod
metadata:
name: my-app-test
annotations:
helm.sh/hook: test
helm.sh/hook-delete-policy: hook-succeeded
spec:
containers:
- name: test-container
image: nginx:1.21
command: ["/bin/sh", "-c", "echo 'test passed'"]
restartPolicy: Never
Note: The
helm.sh/hook annotation tells Helm to run this pod during the test phase.
Warning: Test pods should not be part of the main application deployment and must be cleaned up after execution.
3. Using Test Annotations
| Annotation | Value | Description |
|---|---|---|
| helm.sh/test | test-name |
Defines a test case with the given name. The value must be a valid test name. |
| helm.sh/test-annotation | annotation-value |
Allows adding custom annotations to test cases. |
Example: Defining a Test Case with Annotations
apiVersion: v1
kind: Pod
metadata:
name: test-pod
annotations:
helm.sh/test: my-test-case
helm.sh/test-annotation: custom-value
spec:
containers:
- name: test-container
image: busybox
command: ["sh", "-c", "echo 'Running test'"]
restartPolicy: Never
Note: Test annotations are processed by the Helm test command and must follow the
helm.sh/test naming convention.
4. Running Specific Tests
| Test Type | Description | Command | Notes |
|---|---|---|---|
| Unit Tests | Tests individual chart components in isolation | helm test <release-name> |
Requires test hook in chart templates |
| Integration Tests | Tests chart components as a group in a simulated environment | helm test --timeout 300s <release-name> |
Use timeout to allow longer-running tests |
| Smoke Tests | Basic validation that the chart deploys and runs without errors | helm test --cleanup <release-name> |
Automatically cleans up after test execution |
Note: Ensure that the chart includes test templates in
templates/tests/ directory to run specific tests.
Warning: Tests may fail if dependencies are not properly installed or configured.
5. Viewing Test Logs
| Command | Description | Notes |
|---|---|---|
| helm test <release-name> | Execute tests defined in a chart | Runs all test pods and waits for completion or failure |
| helm test <release-name> --logs | View logs from test pods | Shows detailed output of each test pod after execution |
Note: Test logs are only available if the test pod completes successfully or fails with a non-zero exit code.
Test Log Output Structure
NAME: Name of the test podSTATUS: Status of the test (Running, Completed, Failed)MESSAGE: Message indicating success or failure details
6. Setting Test Timeout
| Property | Values | Description |
|---|---|---|
| test.timeout | 300s |
Timeout for test execution in seconds. Default is 300s (5 minutes). |
| test.timeout | 10m |
Alternative format using minutes. Example: 10 minutes. |
Note: The timeout value must be a valid Go duration string (e.g.,
30s, 5m, 1h). If not specified, Helm uses a default of 300 seconds.
7. Filtering Test Results
| Filter Type | Description | Usage | Notes |
|---|---|---|---|
| --filter | Filter tests by name or label | helm test --filter "name=smoke" |
Supports regex patterns |
| --label | Filter tests by label selector | helm test --label "suite=smoke" |
Multiple labels can be combined with commas |
| --status | Filter tests by status (pass, fail, skip) | helm test --status "fail" |
Can be used to re-run only failed tests |
Note: The
--filter option supports glob patterns for matching test names.
8. Cleaning Test Pods
| Command | Description | Flags |
|---|---|---|
| helm test | Run tests in a Helm release | --cleanup - Delete test pods after completion |
| helm test <release-name> | Run tests for a specific release | --cleanup, --timeout |
Note: The
--cleanup flag ensures that test pods are deleted after the test completes, preventing accumulation of test resources.
9. Testing with Different Values
| Value | Description | Example |
|---|---|---|
| replicaCount | Number of replicas for the deployment | replicaCount: 3 |
| image.repository | Container image repository | image.repository: nginx |
| image.tag | Container image tag | image.tag: "1.21" |
| service.type | Kubernetes service type | service.type: LoadBalancer |
Example: Testing with Different Replica Count
replicaCount: 2
image:
repository: nginx
tag: "1.21"
service:
type: ClusterIP
Example: Testing with Different Image Tag
replicaCount: 1
image:
repository: nginx
tag: "1.20"
service:
type: NodePort
10. Automating Chart Tests
| Test Type | Description | Command | Notes |
|---|---|---|---|
| Unit Tests | Test individual chart templates using helm template |
helm template . --debug |
Use --set to override values during testing |
| Integration Tests | Test chart deployment in a real Kubernetes cluster | helm install my-release . --wait |
Requires a running Kubernetes cluster and kubectl |
| E2E Tests | End-to-end tests using tools like kubeval |
kubeval chart.yaml |
Validates chart structure and Kubernetes manifests |
Note: Integration tests require
kubectl and a running Kubernetes cluster.
Warning: E2E tests may require additional tools like
kubeval or kubetest.