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

Support asserting helm rendering errors #29

Open
gberche-orange opened this issue Dec 22, 2020 · 0 comments
Open

Support asserting helm rendering errors #29

gberche-orange opened this issue Dec 22, 2020 · 0 comments

Comments

@gberche-orange
Copy link

gberche-orange commented Dec 22, 2020

Is your feature request related to a problem? Please describe.

As a helm chart author

  • in order to assert input validation code that trigger rendering error (e.g. using the required function
  • I need hcunit to support assertions on rendering error output

Describe the solution you'd like

Given the following template

apiVersion: servicecatalog.k8s.io/v1beta1
kind: ServiceInstance
metadata:
  namespace: {{ required "A valid namespace is required" .Values.namespace }} # Mandatory since ServiceInstance is a namespaced resource

When helm unit runs with a value missing namespace,

then a render_error hash in the input such as the following is available for assertions to check:

template: "hcunit/templates/serviceinstance.yaml"
message: "error calling required: A valid namespace is required"
statement: "required \"A valid namespace is required\" .Values.namespace>"
line: 5
column: 16

Note: statement, line and column are "nice-to-have". Policies would really need to assert on template and message.

Describe alternatives you've considered

Ignore rendering errors in tests, see for instance test launcher in sample project and associated output below

----------------
Test suite ./unit-tests/mandatory-namespace with user inputs: ./unit-tests/mandatory-namespace/user-inputs/empty-user-inputs.yml  ./unit-tests/mandatory-namespace/user-inputs/mocked-lookup-values.yml 

Checking expected rendering failure in ./unit-tests/mandatory-namespace/policy/service_instance_should_fail_to_render.rego
error while rendering: render error in "hcunit/templates/serviceinstance.yaml": template: hcunit/templates/serviceinstance.yaml:5:16: executing "hcunit/templates/serviceinstance.yaml" at <required "A valid namespace is required" .Values.namespace>: error calling required: A valid namespace is required
Error: plugin "unit" exited with error
helm.go:81: [debug] plugin "unit" exited with error
Ok rendering was rejected as expected

Additional context
Add any other context or screenshots about the feature request here.

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

No branches or pull requests

1 participant