helm-unittest
helm-unittest copied to clipboard
Library testing
Hi
Is it possible to write unittests for library chart?
I know that user cant apply helm template @chart on library chart therefore not sure if it can be unit tested.
Motivation behind is that libraries play crucial role as they contain common _helpers.tpl and therefore we would like to focus on unit testing it to assure the quality and compatibility with charts that depend on it.
Any advice?
Example of tpl from library templates:
{{- define "common.service.tpl" -}}
apiVersion: v1
kind: Service
metadata:
name: {{ template "common.name" .Root }}
labels:
{{- include "common.labels" .Root | nindent 4 }}
spec:
selector:
{{- include "common.selectorLabels" .Root | nindent 4 }}
type: {{ .Values.type }}
ports:
{{- range .Values.ports }}
- port: {{ .port }}
protocol: {{ .protocol | default "TCP" }}
{{- if .targetPort }}
targetPort: {{ .targetPort }}
{{- end }}
{{- if .name }}
name: {{ .name | toString | quote }}
{{- end }}
{{- end }}
{{- end -}}
and test it with:
suite: test service
templates:
- _service.tpl
tests:
- it: should work
asserts:
- isKind:
of: Service
... more asserts ...
Library templates don't generate any input, so it is nog possible to unittest.
I have looked into it by parsing the script itself, bit this resulted in writing almost a complete copy of the actusl template parser.
Greeting @quintush
Maybe is better to call the plugin integrationtest instead of unittest... then less confusion and more precises .
could write another chart on the side that uses the library chart and put the tests there
The library chart can only be tested on a fake chart that uses the library. But this project could simplify a developers' lives by hiding this, i.e. detecting that current chart is a library and creating a fake chart behind the scene, with the library chart as dependency. Wdyt ?
The library chart can only be tested on a fake chart that uses the library. But this project could simplify a developers' lives by hiding this, i.e. detecting that current chart is a library and creating a fake chart behind the scene, with the library chart as dependency. Wdyt ?
I like this idea. Is this something we can get in a future release?