hcunit icon indicating copy to clipboard operation
hcunit copied to clipboard

Support asserting helm rendering errors

Open gberche-orange opened this issue 3 years ago • 0 comments

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.

gberche-orange avatar Dec 22 '20 10:12 gberche-orange