Skip to content

Commit 3c86fd6

Browse files
committed
add unit tests for stackstorm/sensor-mode as it currently is
1 parent 4c16a1b commit 3c86fd6

File tree

2 files changed

+250
-1
lines changed

2 files changed

+250
-1
lines changed

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 labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, ServiceAccount attach, and postStartScript. (#284, #288)
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/unit/st2sensors_test.yaml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
---
2+
suite: Sensors
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
7+
# included templates must also be listed
8+
- configmaps_packs.yaml
9+
- configmaps_rbac.yaml
10+
- configmaps_st2-conf.yaml
11+
- configmaps_st2web.yaml
12+
- secrets_datastore_crypto_key.yaml
13+
- secrets_ssh.yaml
14+
- secrets_st2auth.yaml
15+
- secrets_st2chatops.yaml
16+
17+
tests:
18+
- it: stackstorm/sensor-mode = all-sensors-in-one-pod
19+
template: deployments.yaml
20+
release:
21+
name: foo-release
22+
set:
23+
st2:
24+
packs: { sensors: [] } # ensure only 1 sensor
25+
asserts:
26+
- hasDocuments:
27+
count: 13 # all but st2chatops
28+
29+
- isKind:
30+
of: Deployment
31+
documentIndex: &first_sensor_doc 9
32+
33+
- equal:
34+
path: metadata.name
35+
value: foo-release-st2sensorcontainer
36+
documentIndex: *first_sensor_doc
37+
38+
- equal:
39+
path: metadata.labels.app
40+
value: st2sensorcontainer
41+
documentIndex: *first_sensor_doc
42+
43+
- equal:
44+
path: spec.template.metadata.labels.app
45+
value: st2sensorcontainer
46+
documentIndex: *first_sensor_doc
47+
48+
- equal:
49+
path: spec.selector.matchLabels.app
50+
value: st2sensorcontainer
51+
documentIndex: *first_sensor_doc
52+
53+
- equal:
54+
path: spec.replicas
55+
# sensors should never have more than 1 replica
56+
value: 1
57+
documentIndex: *first_sensor_doc
58+
59+
- equal:
60+
path: spec.template.metadata.annotations.stackstorm/sensor-mode
61+
value: all-sensors-in-one-pod
62+
documentIndex: *first_sensor_doc
63+
64+
- isNull:
65+
path: spec.template.spec.containers[0].command
66+
#- notContains:
67+
# path: spec.template.spec.containers[0].command
68+
# content: '--single-sensor-mode'
69+
documentIndex: *first_sensor_doc
70+
71+
- it: stackstorm/sensor-mode = one-sensor-per-pod
72+
template: deployments.yaml
73+
release:
74+
name: foobarbaz-release
75+
set:
76+
image:
77+
tag: globaldefault
78+
st2sensorcontainer:
79+
image:
80+
tag: sensordefault
81+
st2:
82+
packs:
83+
sensors:
84+
# we define image.tag and securityContext to test overrides
85+
- name: foo
86+
ref: some_pack.foo_sensor
87+
image:
88+
tag: "{{ .Values.image.tag }}templated"
89+
- name: bar
90+
ref: some_pack.bar_sensor
91+
- name: baz
92+
ref: some_pack.baz_sensor
93+
image:
94+
tag: baz
95+
securityContext: &override_security_context
96+
allowPrivilegeEscalation: false
97+
securityContext: &global_security_context
98+
capabilities:
99+
drop: [ALL]
100+
asserts:
101+
- hasDocuments:
102+
count: 15 # all but st2chatops
103+
104+
- isKind:
105+
of: Deployment
106+
documentIndex: *first_sensor_doc
107+
- isKind:
108+
of: Deployment
109+
documentIndex: &second_sensor_doc 10
110+
- isKind:
111+
of: Deployment
112+
documentIndex: &third_sensor_doc 11
113+
114+
- equal:
115+
path: metadata.name
116+
value: foobarbaz-release-st2sensorcontainer-foo
117+
documentIndex: *first_sensor_doc
118+
- equal:
119+
path: metadata.name
120+
value: foobarbaz-release-st2sensorcontainer-bar
121+
documentIndex: *second_sensor_doc
122+
- equal:
123+
path: metadata.name
124+
value: foobarbaz-release-st2sensorcontainer-baz
125+
documentIndex: *third_sensor_doc
126+
127+
- equal:
128+
path: metadata.labels.app
129+
value: st2sensorcontainer-foo
130+
documentIndex: *first_sensor_doc
131+
- equal:
132+
path: metadata.labels.app
133+
value: st2sensorcontainer-bar
134+
documentIndex: *second_sensor_doc
135+
- equal:
136+
path: metadata.labels.app
137+
value: st2sensorcontainer-baz
138+
documentIndex: *third_sensor_doc
139+
140+
- equal:
141+
path: spec.template.metadata.labels.app
142+
value: st2sensorcontainer-foo
143+
documentIndex: *first_sensor_doc
144+
- equal:
145+
path: spec.template.metadata.labels.app
146+
value: st2sensorcontainer-bar
147+
documentIndex: *second_sensor_doc
148+
- equal:
149+
path: spec.template.metadata.labels.app
150+
value: st2sensorcontainer-baz
151+
documentIndex: *third_sensor_doc
152+
153+
- equal:
154+
path: spec.selector.matchLabels.app
155+
value: st2sensorcontainer-foo
156+
documentIndex: *first_sensor_doc
157+
- equal:
158+
path: spec.selector.matchLabels.app
159+
value: st2sensorcontainer-bar
160+
documentIndex: *second_sensor_doc
161+
- equal:
162+
path: spec.selector.matchLabels.app
163+
value: st2sensorcontainer-baz
164+
documentIndex: *third_sensor_doc
165+
166+
- equal: &oneReplica
167+
path: spec.replicas
168+
# sensors should never have more than 1 replica
169+
value: 1
170+
documentIndex: *first_sensor_doc
171+
- equal: *oneReplica
172+
documentIndex: *second_sensor_doc
173+
- equal: *oneReplica
174+
documentIndex: *third_sensor_doc
175+
176+
- equal: &oneSensorAnnotation
177+
path: spec.template.metadata.annotations.stackstorm/sensor-mode
178+
value: one-sensor-per-pod
179+
documentIndex: *first_sensor_doc
180+
- equal: *oneSensorAnnotation
181+
documentIndex: *second_sensor_doc
182+
- equal: *oneSensorAnnotation
183+
documentIndex: *third_sensor_doc
184+
185+
- contains: &singleSensorMode
186+
path: spec.template.spec.containers[0].command
187+
content: '--single-sensor-mode'
188+
documentIndex: *first_sensor_doc
189+
- contains: *singleSensorMode
190+
documentIndex: *second_sensor_doc
191+
- contains: *singleSensorMode
192+
documentIndex: *third_sensor_doc
193+
194+
- contains:
195+
path: spec.template.spec.containers[0].command
196+
content: '--sensor-ref=some_pack.foo_sensor'
197+
documentIndex: *first_sensor_doc
198+
- contains:
199+
path: spec.template.spec.containers[0].command
200+
content: '--sensor-ref=some_pack.bar_sensor'
201+
documentIndex: *second_sensor_doc
202+
- contains:
203+
path: spec.template.spec.containers[0].command
204+
content: '--sensor-ref=some_pack.baz_sensor'
205+
documentIndex: *third_sensor_doc
206+
207+
# make sure value overrides work
208+
# global default > st2sensorcontainer > st2.pack.sensors
209+
# and helm templating works
210+
- matchRegex:
211+
path: spec.template.spec.containers[0].image
212+
pattern: '.*:globaldefaulttemplated$'
213+
documentIndex: *first_sensor_doc
214+
- matchRegex:
215+
path: spec.template.spec.containers[0].image
216+
pattern: '.*:sensordefault$'
217+
documentIndex: *second_sensor_doc
218+
- matchRegex:
219+
path: spec.template.spec.containers[0].image
220+
pattern: '.*:baz$'
221+
documentIndex: *third_sensor_doc
222+
223+
- equal:
224+
path: spec.template.spec.containers[0].securityContext
225+
value: *global_security_context
226+
documentIndex: *first_sensor_doc
227+
- equal:
228+
path: spec.template.spec.containers[0].securityContext
229+
value: *global_security_context
230+
documentIndex: *second_sensor_doc
231+
- equal:
232+
path: spec.template.spec.containers[0].securityContext
233+
value: *override_security_context
234+
documentIndex: *third_sensor_doc
235+
236+
- it: stackstorm/sensor-mode = one-sensor-per-pod fails for missing sensor ref
237+
template: deployments.yaml
238+
release:
239+
name: missing-sensor-ref-release
240+
set:
241+
st2:
242+
packs:
243+
sensors:
244+
- name: foo
245+
ref: some_pack.foo_sensor
246+
- name: bar
247+
asserts:
248+
- failedTemplate:
249+
errorMessage: "You must define `ref` for everything in st2.packs.sensors. This assigns each sensor to a pod."

0 commit comments

Comments
 (0)