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

question on test for "all" template files #320

Open
epDHowwD opened this issue Apr 8, 2024 · 1 comment
Open

question on test for "all" template files #320

epDHowwD opened this issue Apr 8, 2024 · 1 comment
Labels

Comments

@epDHowwD
Copy link

epDHowwD commented Apr 8, 2024

To test that every object has an app label or something like a support link, I would like to formulate a test like this:

suite: test app label
templates:
  - templates/*.yaml
tests:
- it: object has app label
  asserts:
  - equal:
      path: metadata.labels.app
      value: myapp

According to documentSelector this should default select "all" documents within every (*.yaml) template file.

Now the document structure already has some template surrounded by feature flags, so some files might render empty, and thus do not comprise documents.

templates/file-v1.yaml:

{{- if .Values.features.magic }}
  # see file-v2.yaml
{{- else }}
---
kind: ...
{{- end }}

templates/file-v2.yaml:

{{- if .Values.features.magic }}
---
kind: ...
{{- end }}

I would expect that asserts on all documents in all templates would somehow accept empty templates, but the assert fails if not at least one document can be found per template. As I see certainly why asserts should raise if no document is fulfilling the assert, I would like to know if it is possible to test this similarly?

@quintush
Copy link
Contributor

Hello @epDHowwD,

The unittests are indeed very strict in validating "all" templates. So the validation will fail when an empty file is part of the assertions. This setup is by design.

The best way to validate all templates is by ensure "all" template do get generated, which can be done by setting the features.magic values as part of the test. The following namesOveride test shows a similar approach where the assertions are all validated against to mention list of templates, where the ingess.enabled value has been set to true, otherwise the ingress template would result in an empty file (failing the assertion).

Hopes this helps,

Greetings,
@quintush

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

2 participants