Skip to content

Commit af6c707

Browse files
[tavern] Use Manifests Library (#11)
Signed-off-by: Oliver Bähler <[email protected]>
1 parent 33e34bb commit af6c707

File tree

7 files changed

+501
-354
lines changed

7 files changed

+501
-354
lines changed

charts/tavern/Chart.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: tavern
33
description: "Unofficial Tavern Helm Chart"
44
type: application
5-
version: 0.1.3
5+
version: 0.2.0
66
appVersion: 1.0.3
77
home: "https://tavern.readthedocs.io/en/latest/"
88
icon: "https://tavern.readthedocs.io/en/latest/_static/icon.png"
@@ -12,14 +12,14 @@ keywords:
1212
- API testing
1313
- pytest
1414
dependencies:
15-
- name: "library"
16-
version: 0.2.0
17-
repository: https://buttahtoast.github.io/helm-charts/
15+
- name: manifests
16+
version: ">=0.1.0"
17+
repository: https://bedag.github.io/helm-charts
1818
maintainers:
1919
- name: oliverbaehler
2020
2121
- name: chifu1234
22-
22+
2323
annotations:
2424
artifacthub.io/containsSecurityUpdates: "false"
2525
artifacthub.io/prerelease: "true"

charts/tavern/README.md.gotmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Tavern tests are implemented under the key `$.Values.tests`. Each element of thi
4444

4545
## Using Templates
4646

47-
This chart provides the functionality to create templates, which can be rereferenced. The templates allow you to implement go sprig logic and therefor might dramatically improve your tavern test suites.
47+
This chart provides the functionality to create templates, which can be re referenced. The templates allow you to implement go sprig logic and therefor might dramatically improve your tavern test suites.
4848

4949
**NOTE**: While tavern statements use single `{ .. }` I had to replace the go sprig `\{\{ .. }}` as well with single `{ .. }` because of the documenting engine.
5050

charts/tavern/examples/advanced.yaml

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
## Tavern Configuration
2+
tavern:
3+
asCronjob: true
4+
5+
## Job (CronJob) Configuration
6+
# Watch out when having a * as first character.
7+
job:
8+
schedule: "{{ printf \"%s\" \"* * * * 0\" | quote }}"
9+
10+
## Add Extra Resource as Volume
11+
volumes:
12+
- name: scripts
13+
configMap:
14+
name: "{{ cat (include \"lib.utils.fullname\" $) \"-scripts\" | nospace }}"
15+
16+
## Mount custom volume into pod
17+
volumeMounts:
18+
- name: scripts
19+
mountPath: "/scripts"
20+
121

222
## Declare Environment Variables
323
environment:
@@ -8,38 +28,29 @@ environment:
828
- name: "BASIC_AUTH_PASSWD"
929
value: "password"
1030

11-
31+
## Extra Resources
32+
# Manifests compatible extra resoures
1233
extraResources:
1334

1435
## Python Scripts to integrate with Tavern Tests
15-
- apiVersion: v1
16-
kind: ConfigMap
17-
metadata:
18-
name: "{{ cat (include \"lib.utils.fullname\" $) \"-scripts\" | nospace }}"
19-
data:
20-
testing_utils.py: |
21-
def message_says_hello(response):
22-
"""Make sure that the response was friendly
23-
"""
24-
assert response.json().get("message") == "hello world"
25-
26-
## Declare the Configmap as volume
27-
volumes:
28-
- name: scripts
29-
configMap:
30-
name: "{{ cat (include \"lib.utils.fullname\" $) \"-scripts\" | nospace }}"
31-
32-
33-
## Mount the Common Values
34-
volumeMounts:
35-
- name: scripts
36-
mountPath: "/scripts"
36+
- type: "raw"
37+
manifest: |
38+
apiVersion: v1
39+
kind: ConfigMap
40+
metadata:
41+
name: "{{ cat (include "lib.utils.fullname" $) "-scripts" | nospace }}"
42+
data:
43+
testing_utils.py: |
44+
def message_says_hello(response):
45+
"""Make sure that the response was friendly
46+
"""
47+
assert response.json().get("message") == "hello world"
48+
3749
3850
## Custom Value Structure
3951
common:
4052
country: "Switzerland"
4153

42-
4354
## Tavern Stage Templates
4455
stageTemplates:
4556
- name: "http_get"
@@ -121,7 +132,7 @@ tests:
121132
url: '{tavern.env_vars.HOST}/home'
122133
method: GET
123134
json:
124-
country: {{ $.Values.common.country }}
135+
country: "{{ $.Values.common.country }}"
125136
headers:
126137
content-type: "application/json"
127138
response:
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{{/*
2+
3+
Copyright © 2020 Oliver Baehler
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
{{ $t := fromYaml (include "tavern.bundle" $) }}
17+
*/}}
18+
19+
{{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "tavern.bundle" $)) "context" $) | nindent 0 }}
20+
21+
{{/*
22+
Tavern Chart Bundle
23+
*/}}
24+
{{- define "tavern.bundle" -}}
25+
{{- $tavern_tests := (fromYaml (include "tavern.tests" $)) -}}
26+
resources:
27+
{{- if and $.Values.extraResources (kindIs "slice" $.Values.extraResources) }}
28+
{{- toYaml $.Values.extraResources | nindent 2 }}
29+
{{- end }}
30+
{{- if $.Values.tavern.asCronjob }}
31+
- type: "cronjob"
32+
{{- else }}
33+
- type: "job"
34+
{{- end }}
35+
values: {{ toYaml $.Values.job | nindent 6 }}
36+
overwrites:
37+
38+
{{/* VolumeMounts */}}
39+
volumeMounts:
40+
{{- if $.Values.job.volumeMounts }}
41+
{{- toYaml $.Values.job.volumeMounts | nindent 8 }}
42+
{{- end }}
43+
{{- if $tavern_tests.tests }}
44+
volumeMounts:
45+
{{- if $tavern_tests.tests }}
46+
{{- range $tavern_tests.tests }}
47+
- name: {{ .name }}
48+
mountPath: {{ include "tavern.test_directory" $ }}/test_{{ .name }}.tavern.yaml
49+
subPath: {{ .name }}
50+
{{- end }}
51+
{{- end }}
52+
{{- end }}
53+
54+
{{/* Volumes */}}
55+
volumes:
56+
{{- if $.Values.job.volumes }}
57+
{{- toYaml $.Values.job.volumes | nindent 8 }}
58+
{{- end }}
59+
{{- if $tavern_tests.tests }}
60+
{{- range $tavern_tests.tests }}
61+
{{- $ref := include "lib.utils.fullname" (dict "name" .name "context" $) }}
62+
{{- if .secret }}
63+
- name: {{ .name }}
64+
secret:
65+
secretName: {{ $ref }}
66+
defaultMode: {{ $.Values.tavern.defaultMode }}
67+
{{- else }}
68+
- name: {{ .name }}
69+
configMap:
70+
name: {{ $ref }}
71+
defaultMode: {{ $.Values.tavern.defaultMode }}
72+
{{- end }}
73+
{{- end }}
74+
{{- end }}
75+
{{- end }}

charts/tavern/templates/tavern_extraResources.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

charts/tavern/templates/tavern_job.yaml

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)