Skip to content

Commit 524c0e1

Browse files
authored
Merge pull request #288 from StackStorm/helm-unittest
Add unit tests for a variety of chart aspects
2 parents e10d33d + 3c86fd6 commit 524c0e1

13 files changed

+1646
-4
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ jobs:
4242
- name: Run helm-unittest
4343
# by default looks for tests/*_test.yaml
4444
run: |
45-
helm unittest --color --helm3 -f tests/unit/*_test.yaml .
45+
helm unittest --color --helm3 -f 'tests/unit/*_test.yaml' .

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Advanced Feature: Make securityContext (on Deployments/Jobs) and podSecurityContext (on Pods) configurable. This allows dropping all capabilities, for example. You can override the securityContext for `st2actionrunner`, `st2sensorcontainer`, and `st2client` if your actions or sensors need, for example, additional capabilites that the rest of StackStorm does not need. (#271) (by @cognifloyd)
55
* Prefix template helpers with chart name and format helper comments as template comments. (#272) (by @cognifloyd)
66
* New feature: Add `extra_volumes` to all python-based st2 deployments. This can facilitate changing log levels by loading logging conf file(s) from a custom ConfigMap. (#276) (by @cognifloyd)
7-
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for custom annotations. (#284)
7+
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, ServiceAccount attach, postStartScript, and both sensor-modes. (#284, #288)
88

99
## v0.80.0
1010
* Switch st2 to `v3.6` as a new default stable version (#274)

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ helm dependency update
1717

1818
To run the tests manually from the chart's root dir:
1919
```
20-
helm unittest --helm3 -f tests/unit/*_test.yaml .
20+
helm unittest --helm3 -f 'tests/unit/*_test.yaml' .
2121
```
2222

2323
> Note! If you need to add unit tests, file names should follow this pattern: `tests/unit/name_your_test.yaml`

tests/unit/custom_annotations_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ tests:
8989
annotations: *deployment_annotations
9090
st2sensorcontainer:
9191
annotations: *deployment_annotations
92-
st2: { packs: { sensors: [] } } # ensure only 1 sensor
92+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
9393
st2actionrunner:
9494
annotations: *deployment_annotations
9595
st2garbagecollector:

tests/unit/dns_test.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
suite: DNS
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
- jobs.yaml
7+
8+
# included templates must also be listed
9+
- configmaps_packs.yaml
10+
- configmaps_rbac.yaml
11+
- configmaps_st2-conf.yaml
12+
- configmaps_st2-urls.yaml
13+
- configmaps_st2web.yaml
14+
- secrets_datastore_crypto_key.yaml
15+
- secrets_ssh.yaml
16+
- secrets_st2apikeys.yaml
17+
- secrets_st2auth.yaml
18+
- secrets_st2chatops.yaml
19+
20+
tests:
21+
- it: Deployments and Jobs default to no dnsPolicy or dnsConfig
22+
templates:
23+
- deployments.yaml
24+
- jobs.yaml
25+
set:
26+
st2:
27+
packs: { sensors: [] } # ensure only 1 sensor
28+
rbac: { enabled: true } # enable rbac job
29+
asserts:
30+
- isNull:
31+
path: spec.template.spec.dnsPolicy
32+
- isNull:
33+
path: spec.template.spec.dnsConfig
34+
35+
- it: Deployments and Jobs accept custom dnsPolicy or dnsConfig
36+
templates:
37+
- deployments.yaml
38+
- jobs.yaml
39+
set:
40+
dnsPolicy: &dnsPolicy ClusterFirstWithHostNet
41+
dnsConfig: &dnsConfig
42+
nameservers:
43+
- 1.2.3.4
44+
searches:
45+
- ns1.svc.cluster-domain.example
46+
- my.dns.search.suffix
47+
options:
48+
- name: ndots
49+
value: "2"
50+
- name: edns0
51+
st2:
52+
packs: { sensors: [] } # ensure only 1 sensor
53+
rbac: { enabled: true } # enable rbac job
54+
asserts:
55+
- equal:
56+
path: spec.template.spec.dnsPolicy
57+
value: *dnsPolicy
58+
- equal:
59+
path: spec.template.spec.dnsConfig
60+
value: *dnsConfig

tests/unit/image_pull_test.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
suite: Image Pull
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
- jobs.yaml
7+
- service-account.yaml
8+
9+
# included templates must also be listed
10+
- configmaps_packs.yaml
11+
- configmaps_rbac.yaml
12+
- configmaps_st2-conf.yaml
13+
- configmaps_st2-urls.yaml
14+
- configmaps_st2web.yaml
15+
- secrets_datastore_crypto_key.yaml
16+
- secrets_ssh.yaml
17+
- secrets_st2apikeys.yaml
18+
- secrets_st2auth.yaml
19+
- secrets_st2chatops.yaml
20+
21+
# relevant values:
22+
# imagePullPolicy
23+
# image.pullPolicy
24+
# serviceAccount.pullPolicy
25+
# st2.packs.images[].pullPolicy
26+
# imagePullSecreets
27+
# image.pullSecret
28+
# serviceAccount.pullSecret
29+
# st2.packs.images[].pullSecret
30+
31+
tests:
32+
- it: Deployments and Jobs use default pullPolicy and pullSecret
33+
templates:
34+
- deployments.yaml
35+
# st2auth, st2api,
36+
# st2stream, st2web,
37+
# st2rulesengine, st2timersengine,
38+
# st2workflowengine, st2scheduler,
39+
# st2notifier, (1) st2sensorcontainer,
40+
# st2actionrunner, st2garbagecollector,
41+
# st2client, st2chatops
42+
- jobs.yaml
43+
# job-st2-apply-rbac-defintions
44+
# job-st2-apikey-load
45+
# job-st2-key-load
46+
# job-st2-register-content
47+
set:
48+
# image.pullPolicy defaults to IfNotPresent
49+
# image.pullSecret defaults to None
50+
serviceAccount:
51+
create: true
52+
# show that this does not affect pod specs
53+
pullSecret: service-account-pull-secret
54+
st2:
55+
rbac: { enabled: true } # enable rbac job
56+
packs: { sensors: [] } # ensure only 1 sensor
57+
st2chatops:
58+
enabled: true
59+
asserts:
60+
- isNull:
61+
path: spec.template.spec.imagePullSecrets
62+
- equal:
63+
path: spec.template.spec.containers[0].imagePullPolicy
64+
value: IfNotPresent
65+
# path can only select one element, not all initContainers (if present).
66+
#- equal:
67+
# path: 'spec.template.spec.initContainers[].imagePullPolicy'
68+
# value: IfNotPresent
69+
70+
- it: Deployments and Jobs use custom pullPolicy and pullSecret
71+
templates:
72+
- deployments.yaml
73+
- jobs.yaml
74+
set:
75+
image:
76+
pullPolicy: Always
77+
pullSecret: custom-pull-secret
78+
serviceAccount:
79+
create: true
80+
# show that this does not affect pod specs
81+
pullSecret: service-account-pull-secret
82+
st2:
83+
rbac: { enabled: true } # enable rbac job
84+
packs: { sensors: [] } # ensure only 1 sensor
85+
st2chatops:
86+
enabled: true
87+
asserts:
88+
- equal:
89+
path: spec.template.spec.imagePullSecrets[0].name
90+
value: custom-pull-secret
91+
- equal:
92+
path: spec.template.spec.containers[0].imagePullPolicy
93+
value: Always
94+
# path can only select one element, not all initContainers (if present).
95+
#- equal:
96+
# path: 'spec.template.spec.initContainers[].imagePullPolicy'
97+
# value: Always
98+
99+
- it: ServiceAccount has no imagePullSecret by default
100+
template: service-account.yaml
101+
set:
102+
serviceAccount:
103+
create: true
104+
asserts:
105+
- isNull:
106+
path: imagePullSecrets
107+
108+
- it: ServiceAccount accepts custom imagePullSecret
109+
template: service-account.yaml
110+
set:
111+
serviceAccount:
112+
create: true
113+
# show that this does not affect pod specs
114+
pullSecret: service-account-pull-secret
115+
asserts:
116+
- equal:
117+
path: imagePullSecrets[0].name
118+
value: service-account-pull-secret

0 commit comments

Comments
 (0)