quintush / helm-unittest

BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.
MIT License
345 stars 69 forks source link

[question] Testing NamedTemplates in my chart #206

Open grixxie opened 1 year ago

grixxie commented 1 year ago

Hey! First of all I just want to say I'm really impressed and enjoying this plugin :)

I'm fairly new to Helm in general. I've created a namedTemplate which is used in another yaml file in my chart using the include keyword.

I want to test the namedTemplate in isolation - is this possible? I understand that a namedTemplate itself does not generate any output, and am also aware I could test this via the calling yaml; I'm mainly curious whether testing my namedTemplate by itself is possible.

A simple example below:

# NamedTemplate
{{- define "testNamedTemplate" -}}
key: {{ .Values.testValue }}
{{- end -}}
# my test
values: []
templates: []
tests:
  - it:
    template: 'testNamedTemplate.yaml'
    set:
      testValue: 'abc'
    asserts:
      - equal:
          path: key
          value: 'abc'

the above test will give me the error "asserts[0] equal fail".

My "fix" for this right now is to create a file in my chart called testNamedTemplate.include.yaml which is only used for tests, which looks like this:

# testNamedTemplate.include.yaml
{{- include "testNamedTemplate" . -}}

Hopefully this makes sense and isn't too dumb of a question :)

rquinio commented 1 year ago

@grixxie I don't think this is possible, as helm-unitest is basically calling "helm template" programatically,

For info the active repo is now at https://github.com/helm-unittest/helm-unittest