Skip to content

Commit 48a2b1a

Browse files
Feat: Update unittests to support new version of helm unittest (#220)
No changes made to runtime
1 parent 89bcc4d commit 48a2b1a

8 files changed

+54
-41
lines changed

charts/gitops-runtime/tests/app-proxy-image-enrichemnt_test.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests:
1515
app-proxy.image-enrichment.enabled: true
1616
asserts:
1717
- failedTemplate:
18-
errorMessage: 'app-proxy.image-enrichment is enabled but argo-workflows is disabled. This is not suppurted. Either disable erichment or enable workflows'
18+
errorMessage: 'ERROR: app-proxy.image-enrichment is enabled but argo-workflows is disabled. This is not suppurted. Either disable erichment or enable workflows'
1919

2020
- it: Set correct values in app-proxy configmap
2121
template: 'app-proxy/config.yaml'
@@ -31,7 +31,7 @@ tests:
3131
app-proxy.image-enrichment.config.clientHeartbeatIntervalInSeconds: 1
3232
app-proxy.image-enrichment.serviceAccount.name: test
3333
app-proxy.image-enrichment.config.images:
34-
reportImage:
34+
reportImage:
3535
registry: registry.example
3636
repository: codefresh/report-image
3737
tag: 1-test-report
@@ -61,19 +61,19 @@ tests:
6161
- equal:
6262
path: data.enrichmentTtlActiveInSeconds
6363
value: "1"
64-
- equal:
64+
- equal:
6565
path: data.enrichmentClientHeartbeatIntervalInSeconds
6666
value: "1"
67-
- equal:
67+
- equal:
6868
path: data.enrichmentServiceAccountName
6969
value: test
70-
- equal:
70+
- equal:
7171
path: data.enrichmentImageReportingImage
7272
value: registry.example/codefresh/report-image:1-test-report
73-
- equal:
73+
- equal:
7474
path: data.enrichmentGitEnrichmentImage
7575
value: reg.ex/codefresh/git-enrich:1-test-git
76-
- equal:
76+
- equal:
7777
path: data.enrichmentJiraEnrichmentImage
7878
value: my.reg/codefresh/jira-enrich:1-test-jira
7979

@@ -147,7 +147,7 @@ tests:
147147
name: cap-app-proxy-cm
148148
key: enrichmentServiceAccountName
149149
optional: true
150-
- contains:
150+
- contains:
151151
path: spec.template.spec.containers[0].env
152152
content:
153153
name: IRW_REPORT_IMAGE_TASK_IMAGE
@@ -156,7 +156,7 @@ tests:
156156
name: cap-app-proxy-cm
157157
key: enrichmentImageReportingImage
158158
optional: true
159-
- contains:
159+
- contains:
160160
path: spec.template.spec.containers[0].env
161161
content:
162162
name: IRW_GIT_ENRICHMENT_TASK_IMAGE
@@ -165,7 +165,7 @@ tests:
165165
name: cap-app-proxy-cm
166166
key: enrichmentGitEnrichmentImage
167167
optional: true
168-
- contains:
168+
- contains:
169169
path: spec.template.spec.containers[0].env
170170
content:
171171
name: IRW_JIRA_ENRICHMENT_TASK_IMAGE
@@ -202,8 +202,3 @@ tests:
202202
- equal:
203203
path: roleRef.name
204204
value: cap-app-proxy-enrichment
205-
206-
207-
208-
209-

charts/gitops-runtime/tests/argo-projects-templates-integration_test.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Test components that depend on templates from Argo projects.
1+
# Test components that depend on templates from Argo projects.
22
# This is extremely important since currently templates are used that may change between versions of Argo charts.
33
suite: Test integration of outputs from Argo Project templates with components that use them in the runtime chart
44
templates:
@@ -8,9 +8,9 @@ templates:
88
- internal-router/config.yaml
99
- event-reporters/events-reporter/eventsource.yaml
1010
- event-reporters/rollout-reporter/clusterrolebinding.yaml
11-
tests:
11+
tests:
1212
# ------------------------------------------------------------------------
13-
# ArgoCD
13+
# ArgoCD
1414
# Affected templates: app-proxy configmap and events-reporter eventsource
1515
# ------------------------------------------------------------------------
1616
- it: test app proxy argocd url - http
@@ -61,7 +61,7 @@ tests:
6161
path: spec.generic.events.url
6262
value: argo-cd-test-server:443
6363
# ------------------------------------------------------------------------------------------
64-
# Argo Workflows
64+
# Argo Workflows
6565
# Affected templates: app-proxy ClusterRoleBinding to argo-server role, intenal-url config
6666
# ------------------------------------------------------------------------------------------
6767
- it: test app proxy ClusterRoleBinding to argo workflows role
@@ -87,7 +87,7 @@ tests:
8787
argo-workflows.server.secure: true
8888
asserts:
8989
- matchRegex:
90-
path: data.default\.conf\.template
90+
path: data["default.conf.template"]
9191
pattern: .proxy_pass https://argo-test-server:2746+
9292

9393
- it: check worklfow route users argo-workflows server name and protocol http
@@ -101,7 +101,7 @@ tests:
101101
argo-workflows.server.secure: false
102102
asserts:
103103
- matchRegex:
104-
path: data.default\.conf\.template
104+
path: data["default.conf.template"]
105105
pattern: .proxy_pass http://argo-test-server:2746+
106106

107107
- it: test app proxy argocd workflows url - http
@@ -130,7 +130,7 @@ tests:
130130
path: data.argoWorkflowsUrl
131131
value: https://argo-test-server:2746
132132
# ------------------------------------------------------------------------------------------
133-
# Argo rollouts
133+
# Argo rollouts
134134
# Affected templates - rollouts reporter clusterrolebinding
135135
# ------------------------------------------------------------------------------------------
136136
- it: test rollout reporter ClusterRoleBinding to argo rollouts role
@@ -143,4 +143,4 @@ tests:
143143
asserts:
144144
- equal:
145145
path: roleRef.name
146-
value: rollouts-test
146+
value: rollouts-test

charts/gitops-runtime/tests/custom-ca_test.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,25 +379,24 @@ tests:
379379
values:
380380
- ./values/mandatory-values.yaml
381381
asserts:
382-
- isEmpty:
382+
- notExists:
383383
path: spec.triggers[0].template.http.tls
384384

385385
- it: rollout reporter sensor - no tls
386386
template: event-reporters/rollout-reporter/sensor.yaml
387387
values:
388388
- ./values/mandatory-values.yaml
389389
asserts:
390-
- isEmpty:
390+
- notExists:
391391
path: spec.triggers[0].template.http.tls
392392

393393
- it: workflow reporter sensor - no tls
394394
template: event-reporters/workflow-reporter/sensor.yaml
395395
values:
396396
- ./values/mandatory-values.yaml
397397
asserts:
398-
- isEmpty:
398+
- notExists:
399399
path: spec.triggers[0].template.http.tls
400-
401400
# --------------------------------------------------------
402401
# workflowPipelinesGitWebhooks
403402
# --------------------------------------------------------

charts/gitops-runtime/tests/gitops-controller-misc_test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ templates:
66
tests:
77
- it: override both images works
88
template: 'charts/gitops-operator/templates/deployment.yaml'
9+
values:
10+
- ./values/mandatory-values.yaml
911
set:
1012
gitops-operator:
1113
image:
@@ -195,43 +197,54 @@ tests:
195197
kind: ClusterRole
196198
apiVersion: rbac.authorization.k8s.io/v1
197199
name: codefresh-gitops-operator-proxy
200+
any: true
198201
- containsDocument:
199202
kind: ClusterRoleBinding
200203
apiVersion: rbac.authorization.k8s.io/v1
201204
name: codefresh-gitops-operator-proxy
205+
any: true
202206
- containsDocument:
203207
kind: ClusterRoleBinding
204208
apiVersion: rbac.authorization.k8s.io/v1
205209
name: restrictedgitsource-editor
210+
any: true
206211
- containsDocument:
207212
kind: ClusterRole
208213
apiVersion: rbac.authorization.k8s.io/v1
209214
name: restrictedgitsource-editor
215+
any: true
210216
- containsDocument:
211217
kind: ClusterRole
212218
apiVersion: rbac.authorization.k8s.io/v1
213219
name: restrictedgitsource-viewer
220+
any: true
214221
- containsDocument:
215222
kind: ClusterRole
216223
apiVersion: rbac.authorization.k8s.io/v1
217224
name: codefresh-gitops-operator
225+
any: true
218226
- containsDocument:
219227
kind: ClusterRoleBinding
220228
apiVersion: rbac.authorization.k8s.io/v1
221229
name: codefresh-gitops-operator
230+
any: true
222231
- containsDocument:
223232
kind: ClusterRoleBinding
224233
apiVersion: rbac.authorization.k8s.io/v1
225234
name: restrictedgitsource-viewer
235+
any: true
226236
- containsDocument:
227237
kind: Role
228238
apiVersion: rbac.authorization.k8s.io/v1
229239
name: leader-election
240+
any: true
230241
- containsDocument:
231242
kind: Role
232243
apiVersion: rbac.authorization.k8s.io/v1
233244
name: leader-election
245+
any: true
234246
- containsDocument:
235247
kind: RoleBinding
236248
apiVersion: rbac.authorization.k8s.io/v1
237249
name: leader-election
250+
any: true

charts/gitops-runtime/tests/ingress_test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ tests:
5353
tunnel-client.enabled: false
5454
asserts:
5555
- failedTemplate:
56-
errorMessage: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided
56+
errorMessage: "ERROR: When global.runtime.ingress.enabled is false and tunnel-client.enabled is false - global.runtime.ingressUrl must be provided"
5757

5858
- it: fail on ingressUrl that is not http or https
5959
template: templates/codefresh-cm.yaml
@@ -65,7 +65,7 @@ tests:
6565
global.runtime.ingressUrl: test.test.fail
6666
asserts:
6767
- failedTemplate:
68-
errorMessage: Only http and https are supported for global.runtime.ingressUrl
68+
errorMessage: "ERROR: Only http and https are supported for global.runtime.ingressUrl"
6969

7070
- it: codefresh-cm ingressHost is set correctly when ingress enabled
7171
template: templates/codefresh-cm.yaml
@@ -130,4 +130,4 @@ tests:
130130
value:
131131
- hosts:
132132
- "test.example.com"
133-
secretName: blah
133+
secretName: blah

charts/gitops-runtime/tests/runtime-gitcredentials_test.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ tests:
1010
- ./values/mandatory-values.yaml
1111
set:
1212
global.runtime.gitCredentials.password.value: bar
13-
assert:
14-
- contains:
15-
path: metadata
16-
content:
17-
name: test-runtime1-git-password
13+
asserts:
14+
- hasDocuments:
15+
count: 1
1816

1917
- it: secret not created for secretKeyRef
2018
template: 'git-password-secret.yaml'
@@ -23,7 +21,7 @@ tests:
2321
set:
2422
global.runtime.gitCredentials.password.secretKeyRef.name: bar
2523
global.runtime.gitCredentials.password.secretKeyRef.key: foo
26-
assert:
24+
asserts:
2725
- hasDocuments:
2826
count: 0
2927

@@ -71,7 +69,7 @@ tests:
7169
secretKeyRef:
7270
name: bar
7371
key: foo
74-
optional: true
72+
optional: true
7573

7674
- it: Plain text value takes precedence
7775
template: 'app-proxy/deployment.yaml'
@@ -115,4 +113,4 @@ tests:
115113
global.runtime.gitCredentials.password.secretKeyRef.name: foo
116114
asserts:
117115
- failedTemplate:
118-
errorMessage: 'secretKeyRef for global.runtime.gitCredentials.password illegal - must have key field'
116+
errorMessage: 'secretKeyRef for global.runtime.gitCredentials.password illegal - must have key field'

charts/gitops-runtime/tests/workflows-enabled-disabled_test.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tests:
4646
argo-workflows.enabled: false
4747
asserts:
4848
- notMatchRegex:
49-
path: data.default\.conf\.template
49+
path: data["default.conf.template"]
5050
pattern: .+/workflows.+
5151

5252
- it: internal router config has workflows route when workflows enabled
@@ -57,7 +57,7 @@ tests:
5757
argo-workflows.enabled: true
5858
asserts:
5959
- matchRegex:
60-
path: data.default\.conf\.template
60+
path: data["default.conf.template"]
6161
pattern: .+/workflows.+
6262

6363
- it: test app proxy empty argo workflows url when disabled
@@ -69,4 +69,4 @@ tests:
6969
asserts:
7070
- equal:
7171
path: data.argoWorkflowsUrl
72-
value:
72+
value:

scripts/helm-unittests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
## Reference: https://github.com/norwoodj/helm-docs
3+
set -eux
4+
CHART_DIR="$(cd "$(dirname "$0")/.." && pwd)"
5+
echo "$CHART_DIR"
6+
7+
echo "Running Helm unittests"
8+
docker run --entrypoint "/bin/sh" -it --rm -v $CHART_DIR/charts:/charts alpine/helm:3.14.4 -c 'helm plugin install https://github.com/helm-unittest/helm-unittest.git --version 0.5.1 && helm unittest /charts/gitops-runtime'

0 commit comments

Comments
 (0)