Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing a "no template associated with gotpl" error with using helm unittest?

I should start by saying I'm fairly new to the world of helm - however I'm picking up some helm charts developed by others, and looking to add some unit tests. I've installed https://github.com/helm-unittest/helm-unittest, and created a basic test file:

suite: test xyz deployment
templates:
  - xyz-deployment.yaml
tests:
  - it: will not do much yet
    set:
      image.tag: latest
    asserts:
      - isKind:
        of: Deployment

And my chart file structure looks like:

> xyz
  > templates
     xyz.configmap.yaml
     xyz.deployment.yaml
     <others>
  > tests
     xyz_test.yaml

within xyz.deployment.yaml I have (snipped for brevity):

spec:
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/xyz-configmap.yaml") . | sha256sum }}

linting runs cleanly (other than an icon recommendation). However, when I run helm unittest xyz I get:

$ helm unittest xyz

### Chart [ xyz ] xyz

 FAIL  test xyz deployment xyz/tests/xyz_test.yaml
        - deployment should render
                Error: template: xyz/templates/xyz-deployment.yaml:16:30: executing "xyz/templates/xyz-deployment.yaml" at <include (print $.Template.BasePath "/xyz-configmap.yaml") .>: error calling include: template: no template "xyz/templates/xyz-configmap.yaml" associated with template "gotpl"


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

Error: plugin "unittest" exited with error

Clearly the configmap.yaml is there, so I'm at a loss as to why the unit test plugin is reporting it's not found. Can anyone help?

like image 810
Steve H Avatar asked Oct 31 '25 07:10

Steve H


1 Answers

Finally found the answer! Changing my test file to look more like:

suite: test xyz deployment
tests:
  - it: will not do much yet
    set:
      image.tag: latest
    template: xyz-deployment.yaml
    asserts:
      - isKind:
        of: Deployment

ie, specifying the template within the individual spec block, rather than at the top level, worked a treat!

like image 200
Steve H Avatar answered Nov 02 '25 22:11

Steve H