Skip to content

Commit 6d41bf3

Browse files
trbartonafalhambra-hivemq
authored andcommitted
Add flag for enabling/disabling helm tests in hivemq-platform chart
1 parent 0f06fbc commit 6d41bf3

File tree

5 files changed

+244
-2
lines changed

5 files changed

+244
-2
lines changed

charts/hivemq-platform/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ helm uninstall [RELEASE_NAME] -n <namespace>
3737

3838
This removes all Kubernetes components associated with the chart and deletes the release.
3939

40+
## Test the Chart
41+
42+
After installing the chart, you can run Helm tests to verify the release:
43+
44+
```console
45+
helm test [RELEASE_NAME] -n <namespace>
46+
```
47+
48+
This runs a test pod for each exposed MQTT service to verify connectivity to the HiveMQ Platform. Each test pod connects to its respective MQTT service and validates that the connection is working.
49+
50+
To disable test pod creation, set `testing.enabled=false`:
51+
52+
```console
53+
helm install [RELEASE_NAME] hivemq/hivemq-platform -n <namespace> --set testing.enabled=false
54+
```
55+
4056
## Verify the chart
4157

4258
```console
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
{{- if .Values.testing.enabled }}
2+
{{- range $service := .Values.services }}
3+
{{- if and (eq $service.type "mqtt") $service.exposed }}
4+
{{- $serviceName := include "hivemq-platform.range-service-name" (dict "name" $service.name "releaseName" $.Release.Name "type" $service.type "port" $service.port "containerPort" $service.containerPort "legacyPortName" $service.legacyPortName) }}
5+
---
16
apiVersion: v1
27
kind: Pod
38
metadata:
4-
name: "hivemq-test-connection-{{.Release.Name}}"
9+
name: "hivemq-test-connection-{{$.Release.Name}}-{{ $serviceName }}"
510
annotations:
611
"helm.sh/hook": test
712
spec:
@@ -10,5 +15,8 @@ spec:
1015
image: hivemq/mqtt-cli:4.46.0
1116
args: [ "test",
1217
"-h",
13-
"{{ printf "hivemq-%s-mqtt-1883" $.Release.Name | trimAll "-" | trunc 63 | trimSuffix "-" | trim }}" ]
18+
"{{ $serviceName }}" ]
1419
restartPolicy: Never
20+
{{- end }}
21+
{{- end }}
22+
{{- end }}
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
suite: HiveMQ Platform - Testing configuration tests
2+
templates:
3+
- tests/test-mqtt-cli.yml
4+
release:
5+
name: test-platform
6+
tests:
7+
8+
- it: should render test pod by default when MQTT service is exposed
9+
asserts:
10+
- hasDocuments:
11+
count: 1
12+
- containsDocument:
13+
apiVersion: v1
14+
kind: Pod
15+
- matchRegex:
16+
path: metadata.name
17+
pattern: ^hivemq-test-connection-test-platform-hivemq-test-platform-mqtt-\d+$
18+
- equal:
19+
path: metadata.annotations["helm.sh/hook"]
20+
value: test
21+
- equal:
22+
path: spec.containers[0].name
23+
value: hivemq-mqtt-cli
24+
- matchRegex:
25+
path: spec.containers[0].image
26+
pattern: ^hivemq/mqtt-cli:\d+\.\d+\.\d+$
27+
- equal:
28+
path: spec.restartPolicy
29+
value: Never
30+
31+
- it: should not render test pod when testing.enabled is false
32+
set:
33+
testing:
34+
enabled: false
35+
asserts:
36+
- hasDocuments:
37+
count: 0
38+
39+
- it: should not render test pod when no MQTT service is exposed
40+
set:
41+
services:
42+
- type: control-center
43+
exposed: true
44+
port: 8080
45+
containerPort: 8080
46+
asserts:
47+
- hasDocuments:
48+
count: 0
49+
50+
- it: should not render test pod when MQTT service is not exposed
51+
set:
52+
services:
53+
- type: mqtt
54+
exposed: false
55+
port: 1883
56+
containerPort: 1883
57+
asserts:
58+
- hasDocuments:
59+
count: 0
60+
61+
- it: should render test pod with custom MQTT service name
62+
set:
63+
services:
64+
- type: mqtt
65+
name: custom-mqtt-service
66+
exposed: true
67+
port: 1883
68+
containerPort: 1883
69+
asserts:
70+
- hasDocuments:
71+
count: 1
72+
- equal:
73+
path: metadata.name
74+
value: hivemq-test-connection-test-platform-custom-mqtt-service
75+
- contains:
76+
path: spec.containers[0].args
77+
content: -h
78+
- contains:
79+
path: spec.containers[0].args
80+
content: custom-mqtt-service
81+
82+
- it: should render test pod when testing.enabled is explicitly true
83+
set:
84+
testing:
85+
enabled: true
86+
asserts:
87+
- hasDocuments:
88+
count: 1
89+
- containsDocument:
90+
apiVersion: v1
91+
kind: Pod
92+
93+
- it: should fail schema validation when testing.enabled is not a boolean
94+
set:
95+
testing:
96+
enabled: "true"
97+
asserts:
98+
- failedTemplate: {}
99+
100+
- it: should allow testing object with only enabled property
101+
set:
102+
testing:
103+
enabled: true
104+
asserts:
105+
- hasDocuments:
106+
count: 1
107+
108+
- it: should render test pod with default MQTT service when multiple services exist
109+
set:
110+
services:
111+
- type: control-center
112+
exposed: true
113+
port: 8080
114+
containerPort: 8080
115+
- type: mqtt
116+
exposed: true
117+
port: 1883
118+
containerPort: 1883
119+
- type: metrics
120+
exposed: true
121+
port: 9399
122+
containerPort: 9399
123+
asserts:
124+
- hasDocuments:
125+
count: 1
126+
- equal:
127+
path: kind
128+
value: Pod
129+
130+
- it: should use correct test command arguments
131+
asserts:
132+
- equal:
133+
path: spec.containers[0].args[0]
134+
value: test
135+
- equal:
136+
path: spec.containers[0].args[1]
137+
value: -h
138+
- exists:
139+
path: spec.containers[0].args[2]
140+
141+
- it: should have helm test hook annotation
142+
asserts:
143+
- equal:
144+
path: metadata.annotations["helm.sh/hook"]
145+
value: test
146+
147+
- it: should use Never restart policy for test pod
148+
asserts:
149+
- equal:
150+
path: spec.restartPolicy
151+
value: Never
152+
153+
- it: should render one test pod per exposed MQTT service with unique names
154+
set:
155+
services:
156+
- type: mqtt
157+
name: mqtt-primary
158+
exposed: true
159+
port: 1883
160+
containerPort: 1883
161+
- type: mqtt
162+
name: mqtt-secondary
163+
exposed: true
164+
port: 1884
165+
containerPort: 1884
166+
asserts:
167+
- hasDocuments:
168+
count: 2
169+
170+
- it: should render test pods with correct name for multiple MQTT services exposed
171+
set:
172+
services:
173+
- type: mqtt
174+
name: mqtt-primary
175+
exposed: true
176+
port: 1883
177+
containerPort: 1883
178+
- type: mqtt
179+
name: mqtt-secondary
180+
exposed: true
181+
port: 1884
182+
containerPort: 1884
183+
asserts:
184+
- equal:
185+
path: metadata.name
186+
value: hivemq-test-connection-test-platform-mqtt-primary
187+
documentIndex: 0
188+
- equal:
189+
path: spec.containers[0].args[2]
190+
value: mqtt-primary
191+
documentIndex: 0
192+
- equal:
193+
path: metadata.name
194+
value: hivemq-test-connection-test-platform-mqtt-secondary
195+
documentIndex: 1
196+
- equal:
197+
path: spec.containers[0].args[2]
198+
value: mqtt-secondary
199+
documentIndex: 1

charts/hivemq-platform/values.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,16 @@
10471047
},
10481048
"type" : "array"
10491049
},
1050+
"testing" : {
1051+
"description" : "HiveMQ Platform Helm test configuration.",
1052+
"properties" : {
1053+
"enabled" : {
1054+
"description" : "Defines whether Helm test pods should be created. When set to `false`, no test pods are rendered and a `helm test` command will not run any tests.",
1055+
"type" : "boolean"
1056+
}
1057+
},
1058+
"type" : "object"
1059+
},
10501060
"volumeClaimTemplates" : {
10511061
"items" : {
10521062
"properties" : {

charts/hivemq-platform/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,12 @@ monitoring:
853853
# Defines the maximum duration allowed for scraping metrics from the endpoints defined in the ServiceMonitor resource.
854854
# Valid formats include `1d`, `1h30m`, `5m`, and `10s`. Defaults to 10 seconds.
855855
scrapeTimeout: 10s
856+
857+
# HiveMQ Platform Helm test configuration.
858+
testing:
859+
# Defines whether Helm test pods should be created.
860+
# This runs a test pod for each exposed MQTT service to verify connectivity to the HiveMQ Platform.
861+
# Each test pod connects to its respective MQTT service and validates that the connection is working.
862+
# When set to `false`, no test pods are rendered and a `helm test` command will not run any tests.
863+
# The default setting is `true`.
864+
enabled: true

0 commit comments

Comments
 (0)