github.com/migueleliasweb/helm@v2.6.1+incompatible/docs/chart_tests.md (about)

     1  # Chart Tests
     2  
     3  A chart contains a number of Kubernetes resources and components that work together. As a chart author, you may want to write some tests that validate that your chart works as expected when it is installed. These tests also help the chart consumer understand what your chart is supposed to do.
     4  
     5  A **test** in a helm chart lives under the `templates/` directory and is a pod definition that specifies a container with a given command to run. The container should exit successfully (exit 0) for a test to be considered a success. The pod definition must contain one of the helm test hook annotations: `helm.sh/hooks: test-success` or `helm.sh/hooks: test-failure`.
     6  
     7  Example tests:
     8  - Validate that your configuration from the values.yaml file was properly injected.
     9    - Make sure your username and password work correctly
    10    - Make sure an incorrect username and password does not work
    11  - Assert that your services are up and correctly load balancing
    12  - etc.
    13  
    14  You can run the pre-defined tests in Helm on a release using the command `helm test <RELEASE_NAME>`. For a chart consumer, this is a great way to sanity check that their release of a chart (or application) works as expected.
    15  
    16  ## A Breakdown of the Helm Test Hooks
    17  
    18  In Helm, there are two test hooks: `test-success` and `test-failure`
    19  
    20  `test-success` indicates that test pod should complete successfully. In other words, the containers in the pod should exit 0.
    21  `test-failure` is a way to assert that a test pod should not complete successfully. If the containers in the pod do not exit 0, that indicates success.
    22  
    23  ## Example Test
    24  
    25  Here is an example of a helm test pod definition in an example mariadb chart:
    26  
    27  ```
    28  mariadb/
    29    Chart.yaml
    30    README.md
    31    values.yaml
    32    charts/
    33    templates/
    34    templates/tests/test-mariadb-connection.yaml
    35  ```
    36  In `wordpress/templates/tests/test-mariadb-connection.yaml`:
    37  ```
    38  apiVersion: v1
    39  kind: Pod
    40  metadata:
    41    name: "{{ .Release.Name }}-credentials-test"
    42    annotations:
    43      "helm.sh/hook": test-success
    44  spec:
    45    containers:
    46    - name: {{ .Release.Name }}-credentials-test
    47      image: {{ .Values.image }}
    48      env:
    49        - name: MARIADB_HOST
    50          value: {{ template "mariadb.fullname" . }}
    51        - name: MARIADB_PORT
    52          value: "3306"
    53        - name: WORDPRESS_DATABASE_NAME
    54          value: {{ default "" .Values.mariadb.mariadbDatabase | quote }}
    55        - name: WORDPRESS_DATABASE_USER
    56          value: {{ default "" .Values.mariadb.mariadbUser | quote }}
    57        - name: WORDPRESS_DATABASE_PASSWORD
    58          valueFrom:
    59            secretKeyRef:
    60              name: {{ template "mariadb.fullname" . }}
    61              key: mariadb-password
    62      command: ["sh", "-c", "mysql --host=$MARIADB_HOST --port=$MARIADB_PORT --user=$WORDPRESS_DATABASE_USER --password=$WORDPRESS_DATABASE_PASSWORD"]
    63    restartPolicy: Never
    64  ```
    65  
    66  ## Steps to Run a Test Suite on a Release
    67  1. `$ helm install mariadb`
    68  ```
    69  NAME:   quirky-walrus
    70  LAST DEPLOYED: Mon Feb 13 13:50:43 2017
    71  NAMESPACE: default
    72  STATUS: DEPLOYED
    73  ```
    74  
    75  2. `$ helm test quirky-walrus`
    76  ```
    77  RUNNING: quirky-walrus-credentials-test
    78  SUCCESS: quirky-walrus-credentials-test
    79  ```
    80  
    81  ## Notes
    82  - You can define as many tests as you would like in a single yaml file or spread across several yaml files in the `templates/` directory
    83  - You are welcome to nest your test suite under a `tests/` directory like `<chart-name>/templates/tests/` for more isolation