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

Required Values in templates not being tested cause cryptic error messages #68

Closed
AaronKalair opened this issue Oct 2, 2020 · 3 comments · Fixed by #81
Closed

Required Values in templates not being tested cause cryptic error messages #68

AaronKalair opened this issue Oct 2, 2020 · 3 comments · Fixed by #81
Assignees

Comments

@AaronKalair
Copy link

AaronKalair commented Oct 2, 2020

Hi,

Really like this project, and it was good to see Helm 3 support being added!

I was stumped by some cryptic error messages I was getting from Helm Unittest today:

	- manifest should match snapshot

		- asserts[0] `matchSnapshot` fail

			Error:
				template "debug/templates/b.yaml" not exists or not selected in test suite

I've managed to workout what causes it though, if you have required values inside of a Helm Template (Using the required function e.g. {{ required ".someParameter is required" $.Values.someParameter }}.

Then even if you write a test for a different template that doesn't need this value, you get the above error.

To replicate:

helm create debug 
cd debug
rm templates/*
rm -rf templates/tests

Create a.yaml in the templates directory

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ required ".someParameter is required" $.Values.someParameter }}
  namespace: "test"
data:
    a: "a"

Create b.yaml in the templates directory

apiVersion: v1
kind: ConfigMap
metadata:
  name: IDontNeedParameters
  namespace: "iWork"
data:
    b: "b"

Create a test case in tests/b_test.yaml

templates:
  - b.yaml
tests:
  - it: manifest should match snapshot
    asserts:
      - matchSnapshot: {}

Notice that this solely tests b.yaml that has no required values

Run Helm Unit Test

helm unittest -3 .

You'll get this error:

### Chart [ debug ] .

 FAIL  	tests/b_test.yaml
	- manifest should match snapshot

		- asserts[0] `matchSnapshot` fail

			Error:
				template "debug/templates/b.yaml" not exists or not selected in test suite


Charts:      1 failed, 0 passed, 1 total
Test Suites: 1 failed, 0 passed, 1 total
Tests:       1 failed, 0 passed, 1 total
Snapshot:    0 passed, 0 total
Time:        9.265483ms

Set someParameter in the test:

templates:
  - b.yaml
tests:
  - it: manifest should match snapshot
    set:
      someParameter: "fake"
    asserts:
      - matchSnapshot: {}

Run Helm Unit test again

helm unittest -3 .

The tests now pass:

### Chart [ debug ] .

 PASS  	tests/b_test.yaml

Charts:      1 passed, 1 total
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshot:    1 passed, 1 total
Time:        2.310412ms
@quintush
Copy link
Owner

quintush commented Oct 4, 2020

Hello @AaronKalair,

Thanks for the feedback and the clear example.
I will look into this.

Greetings,
@quintush

@AaronKalair
Copy link
Author

Thanks for fixing this!

@0xStarcat
Copy link

I have a similar setup & example using helm's required function, however i'm using the failedTemplate assertion and get this cryptic message: yaml: found character that cannot start any token

When providing a value it goes away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants