-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test code block from _helpers.tpl #288
Comments
I have shared my workaround for the missing functionality with you earlier (#171 (comment)). We have been using this workaround for our tests for library charts. It involves exploiting the |
If I'm understand you correctly, example File {{/*
Return a nodeAffinity definition
{{ include "common.affinities.nodes" . -}}
*/}}
{{- define "common.affinities.nodes" -}}
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
{{- end -}} File apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity: {{- include "common.affinities.nodes" . | nindent 8 }} File ---
templates:
- "pod.yaml"
tests:
- it: should selects the correct kind and match snapshot
documentSelector:
path: kind
value: Pod
asserts:
- matchSnapshot: {}
- it: should validate path exists
asserts:
- exists:
path: spec.affinity.nodeAffinity And snapsho should selects the correct kind and match snapshot:
1: |
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: another-node-label-key
operator: In
values:
- another-node-label-value
weight: 1 Everything just works fine. Are you expecting a feature where functions are |
Thanks a lot, @ivankatliarchuk, appreciate it! We've got some help from the CNCF chat and successfully figured it out. The ticket might be closed. |
Hi @vovkanaz, would you be able to share a solution here too pls so we can spread the knowledge? |
@ivankatliarchuk if I may hijack this ticket. So if you have a Suppose the definition was:
One might call the above template with different contexts e.g. Release.Name, or Values.nameOverride set, with values over 63 characters, and values ending in
This nails down the functionality in that template without needing external resources like Pods or ConfigMaps. Being able to test the template directly has its advantages. I see the suggestion you made earlier as more of an integration test for the chart overall, what I'm looking for here, would be more like a unit test for the tpl file. I hope my question makes sense? |
I would agree on that. Currently charts I'm looking after have quite a decent amount of |
Hello, is there any way to test such code block inside HELM template
{{- include "setAffinity" . | nindent 8 }}
using https://github.com/helm-unittest/helm-unittest, it seems like it doesn't support/work at least for now.
We haven't found any possibility inside this DOC https://github.com/helm-unittest/helm-unittest/blob/main/DOCUMENT.md
The text was updated successfully, but these errors were encountered: