Skip to content

Commit

Permalink
restructure unittests (#417)
Browse files Browse the repository at this point in the history
- renamed unittests directory to differentiate it with helm tests
- added `strict` argument to have strict parsing of tests
- update test to work with helm unittest 0.2.6

After updating helm unittest to version 0.2.6 I got errors as below:

```
	- test additional existing secrets StatefulSet

		- asserts[0] `isKind` fail
			Error: Invalid rendering: no template "jenkins/templates/config.yaml" associated with template "gotpl"
```

To fix it I added `config.yaml` to the list of templates to be rendered
and specified within each test which manifest to use for validation.

Signed-off-by: Torsten Walter <[email protected]>
  • Loading branch information
torstenwalter authored Jul 21, 2021
1 parent 714c97e commit 26affd0
Show file tree
Hide file tree
Showing 27 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
if: steps.list-changed.outputs.changed == 'true'
run: |
helm env
helm plugin install https://github.com/quintush/helm-unittest --version 0.2.4
helm plugin install https://github.com/quintush/helm-unittest --version 0.2.6
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml
Expand Down
4 changes: 4 additions & 0 deletions charts/jenkins/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
.idea/
*.tmproj
ci/
# do not package unittests
unittests/
Tiltfile
.helmignore
4 changes: 4 additions & 0 deletions charts/jenkins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Use the following links to reference issues, PRs, and commits prior to v2.6.0.
The change log until v1.5.7 was auto-generated based on git commits.
Those entries include a reference to the git commit to be able to get more details.

## 3.5.4

Update tests to work with unittest 0.2.6

## 3.5.3

Update Jenkins image and appVersion to jenkins lts release version 2.289.2
Expand Down
2 changes: 1 addition & 1 deletion charts/jenkins/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: jenkins
home: https://jenkins.io/
version: 3.5.3
version: 3.5.4
appVersion: 2.289.2
description: Jenkins - Build great things at any scale! The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
sources:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ release:
namespace: my-namespace
templates:
- jenkins-controller-statefulset.yaml
- config.yaml
tests:
- it: default values
template: jenkins-controller-statefulset.yaml
asserts:
- isKind:
of: StatefulSet
Expand Down Expand Up @@ -194,6 +196,7 @@ tests:
secret:
secretName: my-release-jenkins
- it: test different values
template: jenkins-controller-statefulset.yaml
capabilities:
apiVersions:
- scheduling.k8s.io/v1beta1
Expand Down Expand Up @@ -297,6 +300,7 @@ tests:
path: spec.updateStrategy.type
value: OnDelete
- it: configure image tag
template: jenkins-controller-statefulset.yaml
set:
controller.tag: 2.249.1-slim
controller.imagePullPolicy: IfNotPresent
Expand All @@ -308,6 +312,7 @@ tests:
path: spec.template.spec.containers[0].imagePullPolicy
value: IfNotPresent
- it: custom image
template: jenkins-controller-statefulset.yaml
set:
controller:
image: registry/image
Expand All @@ -324,6 +329,7 @@ tests:
value: >-
-Dcasc.reload.token=$(POD_NAME) -Dio.jenkins.plugins.kubernetes.disableNoDelayProvisioning=true
- it: disable helm.sh label
template: jenkins-controller-statefulset.yaml
set:
renderHelmLabels: false
asserts:
Expand All @@ -335,6 +341,7 @@ tests:
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: jenkins
- it: java & jenkins opts with quotes
template: jenkins-controller-statefulset.yaml
set:
controller:
javaOpts: >-
Expand All @@ -355,6 +362,7 @@ tests:
value: >-
-Dtest="custom: 'true'"
- it: test empty controller.podSecurityContextOverride
template: jenkins-controller-statefulset.yaml
set:
controller:
podSecurityContextOverride: {}
Expand All @@ -363,6 +371,7 @@ tests:
path: spec.template.spec.securityContext
value: {}
- it: test controller.podSecurityContextOverride
template: jenkins-controller-statefulset.yaml
set:
controller:
podSecurityContextOverride:
Expand All @@ -378,6 +387,7 @@ tests:
supplementalGroups:
- 5555
- it: test 2 additional secrets
template: jenkins-controller-statefulset.yaml
set:
controller.additionalSecrets:
- name: something
Expand Down Expand Up @@ -406,6 +416,7 @@ tests:
secret:
secretName: my-release-jenkins-additional-secrets
- it: test templated environment variables
template: jenkins-controller-statefulset.yaml
set:
testValue: some-value
controller.initContainerEnv:
Expand Down Expand Up @@ -455,6 +466,7 @@ tests:
name: "TEST_ENV_VAR__CONTAINER_TEMPLATED"
value: 'some-value'
- it: overrides container args
template: jenkins-controller-statefulset.yaml
set:
controller.overrideArgs:
- --httpPort=8080
Expand All @@ -466,11 +478,12 @@ tests:
- --httpPort=8080
- --requestHeaderSize=32768
- it: render pod annotations
template: jenkins-controller-statefulset.yaml
set:
controller:
podAnnotations:
templated-annotations: '{{ .Release.Name }}'
fixed-annotation: some-fixed-annotation
asserts:
- matchSnapshot:
path: spec.template.metadata.annotations
path: spec.template.metadata.annotations
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ release:
namespace: my-namespace
templates:
- jenkins-controller-statefulset.yaml
- config.yaml
tests:
- it: test additional existing secrets StatefulSet
template: jenkins-controller-statefulset.yaml
set:
controller.additionalExistingSecrets:
- name: secret-name-1
Expand Down Expand Up @@ -40,4 +42,4 @@ tests:
value:
name: secret-name-1-password
secret:
secretName: secret-name-1
secretName: secret-name-1
File renamed without changes.
2 changes: 1 addition & 1 deletion ct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ chart-dirs:
- charts
helm-extra-args: --timeout 600s
additional-commands:
- helm unittest --helm3 -f tests/*.yaml {{ .Path }}
- helm unittest --helm3 --strict -f 'unittests/*.yaml' {{ .Path }}

0 comments on commit 26affd0

Please sign in to comment.