Skip to content

Commit cae3da0

Browse files
committed
Refactor unit tests to support unittests v0.4.4
Implements #414
1 parent 80f80b4 commit cae3da0

19 files changed

+154
-153
lines changed

.github/workflows/unit.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# We should periodically check to see if another fork has taken over maintenance,
3636
# as the de-facto "best" fork has changed several times over the years.
3737
run: |
38-
helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11
38+
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.4.4
3939
4040
- name: Install chart dependencies
4141
run: |
@@ -44,4 +44,4 @@ jobs:
4444
- name: Run helm-unittest
4545
# by default looks for tests/*_test.yaml
4646
run: |
47-
helm unittest --color --helm3 -f 'tests/unit/*_test.yaml' .
47+
helm unittest --color -f 'tests/unit/*_test.yaml' .

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Development
4+
* 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)
45

56
## v1.1.0
67
* Fix syntax with ensure-packs-volumes-are-writable job (#403, #411) (by @skiedude)

templates/deployments.yaml

+13-13
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ spec:
3838
{{- toYaml .Values.st2auth.annotations | nindent 8 }}
3939
{{- end }}
4040
spec:
41-
imagePullSecrets:
4241
{{- if .Values.image.pullSecret }}
42+
imagePullSecrets:
4343
- name: {{ .Values.image.pullSecret }}
4444
{{- end }}
4545
initContainers:
@@ -177,8 +177,8 @@ spec:
177177
{{- toYaml .Values.st2api.annotations | nindent 8 }}
178178
{{- end }}
179179
spec:
180-
imagePullSecrets:
181180
{{- if .Values.image.pullSecret }}
181+
imagePullSecrets:
182182
- name: {{ .Values.image.pullSecret }}
183183
{{- end }}
184184
{{- if .Values.st2.packs.images }}
@@ -316,8 +316,8 @@ spec:
316316
{{- toYaml .Values.st2stream.annotations | nindent 8 }}
317317
{{- end }}
318318
spec:
319-
imagePullSecrets:
320319
{{- if .Values.image.pullSecret }}
320+
imagePullSecrets:
321321
- name: {{ .Values.image.pullSecret }}
322322
{{- end }}
323323
initContainers:
@@ -426,8 +426,8 @@ spec:
426426
{{- toYaml .Values.st2web.annotations | nindent 8 }}
427427
{{- end }}
428428
spec:
429-
imagePullSecrets:
430429
{{- if .Values.image.pullSecret }}
430+
imagePullSecrets:
431431
- name: {{ .Values.image.pullSecret }}
432432
{{- end }}
433433
terminationGracePeriodSeconds: {{ .Values.st2web.terminationGracePeriodSeconds | default 30 }}
@@ -565,8 +565,8 @@ spec:
565565
{{- toYaml .Values.st2rulesengine.annotations | nindent 8 }}
566566
{{- end }}
567567
spec:
568-
imagePullSecrets:
569568
{{- if .Values.image.pullSecret }}
569+
imagePullSecrets:
570570
- name: {{ .Values.image.pullSecret }}
571571
{{- end }}
572572
initContainers:
@@ -683,8 +683,8 @@ spec:
683683
{{- toYaml .Values.st2timersengine.annotations | nindent 8 }}
684684
{{- end }}
685685
spec:
686-
imagePullSecrets:
687686
{{- if .Values.image.pullSecret }}
687+
imagePullSecrets:
688688
- name: {{ .Values.image.pullSecret }}
689689
{{- end }}
690690
initContainers:
@@ -791,8 +791,8 @@ spec:
791791
{{- end }}
792792
spec:
793793
terminationGracePeriodSeconds: {{ .Values.st2workflowengine.terminationGracePeriodSeconds | default 300 }}
794-
imagePullSecrets:
795794
{{- if .Values.image.pullSecret }}
795+
imagePullSecrets:
796796
- name: {{ .Values.image.pullSecret }}
797797
{{- end }}
798798
initContainers:
@@ -910,8 +910,8 @@ spec:
910910
{{- toYaml .Values.st2scheduler.annotations | nindent 8 }}
911911
{{- end }}
912912
spec:
913-
imagePullSecrets:
914913
{{- if .Values.image.pullSecret }}
914+
imagePullSecrets:
915915
- name: {{ .Values.image.pullSecret }}
916916
{{- end }}
917917
initContainers:
@@ -1027,8 +1027,8 @@ spec:
10271027
{{- toYaml .Values.st2notifier.annotations | nindent 8 }}
10281028
{{- end }}
10291029
spec:
1030-
imagePullSecrets:
10311030
{{- if .Values.image.pullSecret }}
1031+
imagePullSecrets:
10321032
- name: {{ .Values.image.pullSecret }}
10331033
{{- end }}
10341034
initContainers:
@@ -1173,8 +1173,8 @@ spec:
11731173
{{- toYaml $sensor.annotations | nindent 8 }}
11741174
{{- end }}
11751175
spec:
1176-
imagePullSecrets:
11771176
{{- if $.Values.image.pullSecret }}
1177+
imagePullSecrets:
11781178
- name: {{ $.Values.image.pullSecret }}
11791179
{{- end }}
11801180
{{- if $.Values.st2.packs.images }}
@@ -1354,8 +1354,8 @@ spec:
13541354
hostAliases:
13551355
{{- toYaml .Values.st2actionrunner.hostAliases | nindent 8 }}
13561356
{{- end }}
1357-
imagePullSecrets:
13581357
{{- if .Values.image.pullSecret }}
1358+
imagePullSecrets:
13591359
- name: {{ .Values.image.pullSecret }}
13601360
{{- end }}
13611361
{{- if .Values.st2.packs.images }}
@@ -1501,8 +1501,8 @@ spec:
15011501
{{- toYaml .Values.st2garbagecollector.annotations | nindent 8 }}
15021502
{{- end }}
15031503
spec:
1504-
imagePullSecrets:
15051504
{{- if .Values.image.pullSecret }}
1505+
imagePullSecrets:
15061506
- name: {{ .Values.image.pullSecret }}
15071507
{{- end }}
15081508
initContainers:
@@ -1615,11 +1615,11 @@ spec:
16151615
{{- toYaml .Values.st2client.annotations | nindent 8 }}
16161616
{{- end }}
16171617
spec:
1618-
imagePullSecrets:
16191618
{{- if .Values.st2.packs.images }}
16201619
{{- include "stackstorm-ha.packs-pullSecrets" . | nindent 6 }}
16211620
{{- end }}
16221621
{{- if .Values.image.pullSecret }}
1622+
imagePullSecrets:
16231623
- name: {{ .Values.image.pullSecret }}
16241624
{{- end }}
16251625
initContainers:

templates/jobs.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ spec:
2525
{{- toYaml .Values.jobs.annotations | nindent 8 }}
2626
{{- end }}
2727
spec:
28-
imagePullSecrets:
2928
{{- if .Values.image.pullSecret }}
29+
imagePullSecrets:
3030
- name: {{ .Values.image.pullSecret }}
3131
{{- end }}
3232
containers:
@@ -127,8 +127,8 @@ spec:
127127
{{- toYaml .Values.jobs.annotations | nindent 8 }}
128128
{{- end }}
129129
spec:
130-
imagePullSecrets:
131130
{{- if .Values.image.pullSecret }}
131+
imagePullSecrets:
132132
- name: {{ .Values.image.pullSecret }}
133133
{{- end }}
134134
initContainers:
@@ -266,8 +266,8 @@ spec:
266266
{{- toYaml .Values.jobs.annotations | nindent 8 }}
267267
{{- end }}
268268
spec:
269-
imagePullSecrets:
270269
{{- if .Values.image.pullSecret }}
270+
imagePullSecrets:
271271
- name: {{ .Values.image.pullSecret }}
272272
{{- end }}
273273
initContainers:
@@ -398,8 +398,8 @@ spec:
398398
{{- toYaml .Values.jobs.annotations | nindent 8 }}
399399
{{- end }}
400400
spec:
401-
imagePullSecrets:
402401
{{- if .Values.image.pullSecret }}
402+
imagePullSecrets:
403403
- name: {{ .Values.image.pullSecret }}
404404
{{- end }}
405405
{{- if $.Values.st2.packs.images -}}
@@ -512,8 +512,8 @@ spec:
512512
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
513513
{{- end }}
514514
spec:
515-
imagePullSecrets:
516515
{{- if $.Values.image.pullSecret }}
516+
imagePullSecrets:
517517
- name: {{ $.Values.image.pullSecret }}
518518
{{- end }}
519519
initContainers: []
@@ -633,8 +633,8 @@ spec:
633633
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
634634
{{- end }}
635635
spec:
636-
imagePullSecrets:
637636
{{- if $.Values.image.pullSecret }}
637+
imagePullSecrets:
638638
- name: {{ $.Values.image.pullSecret }}
639639
{{- end }}
640640
{{- if $.Values.st2.packs.images -}}

tests/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ This directory contains Helm chart unit and integration tests (under `tests/unit
44

55
## Unit tests
66

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

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

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

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

2727
## Integration tests
2828

tests/unit/custom_annotations_test.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tests:
3131
foo: bar
3232
answer: "42"
3333
asserts: &annotations_asserts
34-
- isNotNull:
34+
- exists:
3535
path: metadata.annotations
3636
- equal:
3737
path: metadata.annotations.foo
@@ -125,7 +125,7 @@ tests:
125125
# st2client, st2chatops
126126

127127
# deployment annotations
128-
- isNotNull:
128+
- exists:
129129
path: metadata.annotations
130130
- equal:
131131
path: metadata.annotations.foo
@@ -135,7 +135,7 @@ tests:
135135
value: "42"
136136

137137
# pod annotations
138-
- isNotNull:
138+
- exists:
139139
path: spec.template.metadata.annotations
140140
- equal:
141141
path: spec.template.metadata.annotations.foo
@@ -188,7 +188,7 @@ tests:
188188
# extra_hooks job
189189

190190
# job annotations
191-
- isNotNull:
191+
- exists:
192192
path: metadata.annotations
193193
- equal:
194194
path: metadata.annotations.foo
@@ -198,7 +198,7 @@ tests:
198198
value: "42"
199199

200200
# pod annotations
201-
- isNotNull:
201+
- exists:
202202
path: spec.template.metadata.annotations
203203
- equal:
204204
path: spec.template.metadata.annotations.foo

tests/unit/dns_test.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ tests:
5151
hook_weight: -5
5252
command: ["st2", "run", "--tail", "custom_pack.warn_about_upgrade"]
5353
asserts:
54-
- isNull:
54+
- notExists:
5555
path: spec.template.spec.dnsPolicy
56-
- isNull:
56+
- notExists:
5757
path: spec.template.spec.dnsConfig
5858

5959
- it: Deployments and Jobs accept custom dnsPolicy or dnsConfig

tests/unit/env_test.yaml

+16-16
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,32 @@ tests:
3434
- name: ST2CLIENT
3535
value: "1"
3636
documentIndex: 12
37-
- isNull: &is_null_env
37+
- notExists: &is_null_env
3838
path: spec.template.spec.containers[0].env
3939
documentIndex: 0
40-
- isNull: *is_null_env
40+
- notExists: *is_null_env
4141
documentIndex: 1
42-
- isNull: *is_null_env
42+
- notExists: *is_null_env
4343
documentIndex: 2
44-
- isNull: *is_null_env
44+
- notExists: *is_null_env
4545
documentIndex: 3
46-
- isNull: *is_null_env
46+
- notExists: *is_null_env
4747
documentIndex: 4
48-
- isNull: *is_null_env
48+
- notExists: *is_null_env
4949
documentIndex: 5
50-
- isNull: *is_null_env
50+
- notExists: *is_null_env
5151
documentIndex: 6
52-
- isNull: *is_null_env
52+
- notExists: *is_null_env
5353
documentIndex: 7
54-
- isNull: *is_null_env
54+
- notExists: *is_null_env
5555
documentIndex: 8
56-
- isNull: *is_null_env
56+
- notExists: *is_null_env
5757
documentIndex: 9
58-
- isNull: *is_null_env
58+
- notExists: *is_null_env
5959
documentIndex: 10
60-
- isNull: *is_null_env
60+
- notExists: *is_null_env
6161
documentIndex: 11
62-
- isNull: *is_null_env
62+
- notExists: *is_null_env
6363
documentIndex: 13
6464

6565
- it: Jobs default to no env
@@ -76,7 +76,7 @@ tests:
7676
asserts:
7777
- hasDocuments:
7878
count: 5
79-
- isNull: *is_null_env
79+
- notExists: *is_null_env
8080

8181
- it: Deployments accept custom env
8282
template: deployments.yaml
@@ -177,10 +177,10 @@ tests:
177177
- contains: *contains_st2_urls
178178
documentIndex: 2
179179

180-
- isNull: &is_null_envFrom
180+
- notExists: &is_null_envFrom
181181
path: spec.template.spec.containers[0].envFrom
182182
documentIndex: 0
183-
- isNull: *is_null_envFrom
183+
- notExists: *is_null_envFrom
184184
documentIndex: 3
185185

186186
- it: Deployments support envFromSecrets (st2actionrunner, st2sensorcontainer, and st2client)

0 commit comments

Comments
 (0)