Skip to content
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

$.Template.BasePath can't be handled properly #293

Closed
cyfu opened this issue Feb 4, 2024 · 4 comments
Closed

$.Template.BasePath can't be handled properly #293

cyfu opened this issue Feb 4, 2024 · 4 comments
Labels

Comments

@cyfu
Copy link

cyfu commented Feb 4, 2024

I added following annotation in helm-unittest/test/data/v3/with-subchart/charts/child-chart/templates/deployment.yaml.

annotations:
  checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}

And also created the configmap.yaml file in the child-chart/templates folder.

helm template command works well, but helm unittest . produces error:

Error: template: with-subchart/charts/child-chart/templates/deployment.yaml:12:24: executing "with-subchart/charts/child-chart/templates/deployment.yaml" at <include (print $.Template.BasePath "/configmap.yaml") .>: error calling include: template: no template "with-subchart/charts/child-chart/templates/configmap.yaml" associated with template "gotpl"

Attached is the modified with-subchart and console output.
with-subchart2.zip
console_output.txt

@instriker
Copy link

Same issue.

What we are doing in our case is including a sub-chart template to do some dynamic adjustements. This was working with unit test 0.2.8, but stopped working when upgrading to 0.4.1:

{{- $filePath := ( print $.Template.BasePath "../charts/testkube/charts/testkube-api/templates/minio.yaml" ) }}
{{- $filePath = $filePath | replace "templates/../" ""}}
{{- $manifest := include "filePath" $someContext }}

@quintush
Copy link
Contributor

Hello @cyfu, @instriker,

Please take a look at the deployment test in the basic sample project.

To run the tpl functions the helmchart expects that the linked yaml files are part of the helmcht
To isolated the unit tests, the template filter only loads the required files. So to have a valid deployment test with a validation of the configmap hash, it is important to also include the configmap.yaml as part of the templates filter.

Greetings,
@quintush

@instriker
Copy link

Yes it works, thank you!

I didn't figure the best way to handle the templates to reference files inside a chart.yaml, but found *.yaml to be working as in this config:

templates:
- "*.yaml"
tests:
- it: my test
  template: templates/deployment.yaml
  asserts: 
  # ...

@cyfu
Copy link
Author

cyfu commented Feb 18, 2024

Thanks @quintush , it works for me.

@cyfu cyfu closed this as completed Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants