Skip to content

Commit

Permalink
Refactor unit tests to support unittests v0.4.4 (#417)
Browse files Browse the repository at this point in the history
Implements #414
  • Loading branch information
jk464 authored May 9, 2024
1 parent 80f80b4 commit 496fc58
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# We should periodically check to see if another fork has taken over maintenance,
# as the de-facto "best" fork has changed several times over the years.
run: |
helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.4.4
- name: Install chart dependencies
run: |
Expand All @@ -44,4 +44,4 @@ jobs:
- name: Run helm-unittest
# by default looks for tests/*_test.yaml
run: |
helm unittest --color --helm3 -f 'tests/unit/*_test.yaml' .
helm unittest --color -f 'tests/unit/*_test.yaml' .
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Development
* Updated our tests/unit to support newer versions of `unittests` - for now bumping to `v0.4.4` as `v0.5.0` has a bug that impacts us (see helm-unittest/helm-unittest#329), but testing around the bug shows `v0.5.x` should also "just work" (#414) (by @jk464)

## v1.1.0
* Fix syntax with ensure-packs-volumes-are-writable job (#403, #411) (by @skiedude)
Expand Down
26 changes: 13 additions & 13 deletions templates/deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ spec:
{{- toYaml .Values.st2auth.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -177,8 +177,8 @@ spec:
{{- toYaml .Values.st2api.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.images }}
Expand Down Expand Up @@ -316,8 +316,8 @@ spec:
{{- toYaml .Values.st2stream.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -426,8 +426,8 @@ spec:
{{- toYaml .Values.st2web.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.st2web.terminationGracePeriodSeconds | default 30 }}
Expand Down Expand Up @@ -565,8 +565,8 @@ spec:
{{- toYaml .Values.st2rulesengine.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -683,8 +683,8 @@ spec:
{{- toYaml .Values.st2timersengine.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -791,8 +791,8 @@ spec:
{{- end }}
spec:
terminationGracePeriodSeconds: {{ .Values.st2workflowengine.terminationGracePeriodSeconds | default 300 }}
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -910,8 +910,8 @@ spec:
{{- toYaml .Values.st2scheduler.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -1027,8 +1027,8 @@ spec:
{{- toYaml .Values.st2notifier.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -1173,8 +1173,8 @@ spec:
{{- toYaml $sensor.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if $.Values.image.pullSecret }}
imagePullSecrets:
- name: {{ $.Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images }}
Expand Down Expand Up @@ -1354,8 +1354,8 @@ spec:
hostAliases:
{{- toYaml .Values.st2actionrunner.hostAliases | nindent 8 }}
{{- end }}
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.images }}
Expand Down Expand Up @@ -1501,8 +1501,8 @@ spec:
{{- toYaml .Values.st2garbagecollector.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -1615,11 +1615,11 @@ spec:
{{- toYaml .Values.st2client.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.st2.packs.images }}
{{- include "stackstorm-ha.packs-pullSecrets" . | nindent 6 }}
{{- end }}
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down
12 changes: 6 additions & 6 deletions templates/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ spec:
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
containers:
Expand Down Expand Up @@ -127,8 +127,8 @@ spec:
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -266,8 +266,8 @@ spec:
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
Expand Down Expand Up @@ -398,8 +398,8 @@ spec:
{{- toYaml .Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if .Values.image.pullSecret }}
imagePullSecrets:
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images -}}
Expand Down Expand Up @@ -512,8 +512,8 @@ spec:
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if $.Values.image.pullSecret }}
imagePullSecrets:
- name: {{ $.Values.image.pullSecret }}
{{- end }}
initContainers: []
Expand Down Expand Up @@ -633,8 +633,8 @@ spec:
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- if $.Values.image.pullSecret }}
imagePullSecrets:
- name: {{ $.Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images -}}
Expand Down
6 changes: 3 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This directory contains Helm chart unit and integration tests (under `tests/unit

## Unit tests

Unit tests (`tests/unit/*_test.yaml`) use [`helm-unittest`](https://github.com/quintush/helm-unittest).
Unit tests (`tests/unit/*_test.yaml`) use [`helm-unittest`](https://github.com/helm-unittest/helm-unittest).
`helm-unittest` uses a yaml-based test file to ensure that the templates generate expected features.
For example, they can ensure that custom annotations are applied consistently to all of the deployments.
Unit tests do not require a running kubernetes cluster.

Before running unit tests, install the `helm-unittest` plugin and ensure you have sub-charts installed:
```
helm plugin install https://github.com/quintush/helm-unittest
$ helm plugin install https://github.com/helm-unittest/helm-unittest.git
helm dependency update
```

Expand All @@ -22,7 +22,7 @@ helm unittest --helm3 -f 'tests/unit/*_test.yaml' .

> Note! If you need to add unit tests, file names should follow this pattern: `tests/unit/name_your_test.yaml`
See https://github.com/quintush/helm-unittest/blob/master/DOCUMENT.md for details on writing unit tests.
See https://github.com/helm-unittest/helm-unittest/blob/master/DOCUMENT.md for details on writing unit tests.

## Integration tests

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/custom_annotations_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tests:
foo: bar
answer: "42"
asserts: &annotations_asserts
- isNotNull:
- exists:
path: metadata.annotations
- equal:
path: metadata.annotations.foo
Expand Down Expand Up @@ -125,7 +125,7 @@ tests:
# st2client, st2chatops

# deployment annotations
- isNotNull:
- exists:
path: metadata.annotations
- equal:
path: metadata.annotations.foo
Expand All @@ -135,7 +135,7 @@ tests:
value: "42"

# pod annotations
- isNotNull:
- exists:
path: spec.template.metadata.annotations
- equal:
path: spec.template.metadata.annotations.foo
Expand Down Expand Up @@ -188,7 +188,7 @@ tests:
# extra_hooks job

# job annotations
- isNotNull:
- exists:
path: metadata.annotations
- equal:
path: metadata.annotations.foo
Expand All @@ -198,7 +198,7 @@ tests:
value: "42"

# pod annotations
- isNotNull:
- exists:
path: spec.template.metadata.annotations
- equal:
path: spec.template.metadata.annotations.foo
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/dns_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ tests:
hook_weight: -5
command: ["st2", "run", "--tail", "custom_pack.warn_about_upgrade"]
asserts:
- isNull:
- notExists:
path: spec.template.spec.dnsPolicy
- isNull:
- notExists:
path: spec.template.spec.dnsConfig

- it: Deployments and Jobs accept custom dnsPolicy or dnsConfig
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/env_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ tests:
- name: ST2CLIENT
value: "1"
documentIndex: 12
- isNull: &is_null_env
- notExists: &is_null_env
path: spec.template.spec.containers[0].env
documentIndex: 0
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 1
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 2
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 3
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 4
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 5
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 6
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 7
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 8
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 9
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 10
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 11
- isNull: *is_null_env
- notExists: *is_null_env
documentIndex: 13

- it: Jobs default to no env
Expand All @@ -76,7 +76,7 @@ tests:
asserts:
- hasDocuments:
count: 5
- isNull: *is_null_env
- notExists: *is_null_env

- it: Deployments accept custom env
template: deployments.yaml
Expand Down Expand Up @@ -177,10 +177,10 @@ tests:
- contains: *contains_st2_urls
documentIndex: 2

- isNull: &is_null_envFrom
- notExists: &is_null_envFrom
path: spec.template.spec.containers[0].envFrom
documentIndex: 0
- isNull: *is_null_envFrom
- notExists: *is_null_envFrom
documentIndex: 3

- it: Deployments support envFromSecrets (st2actionrunner, st2sensorcontainer, and st2client)
Expand Down
Loading

0 comments on commit 496fc58

Please sign in to comment.