helm-unittest icon indicating copy to clipboard operation
helm-unittest copied to clipboard

helm-unittest plugin fails to test sections which are applied from library chart

Open raghav19 opened this issue 3 years ago • 3 comments

I recently have developed a library chart for a certain set of functions which is added as a dependency in another chart. The dependency is updated using the helm dep update <my-chart> command.

The config-pvc.yaml using the library chart is as follows

{{- include "factory.headers" . }}
---
{{- include "factory.pvcConfigCommonSpec" . }}
  storageClassName: nfs
  accessModes:
    - {{ .Values.storage.nfs.accessModes }}
  resources:
    requests:
      storage: {{ .Values.storage.nfs.configSize }}

The library function written under a lib chart under templates/_pvc.tpl is as follows

{{/*
PVC for config
*/}}
{{- define "factory.pvcConfigCommonSpec" -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {{ include "factory.name" . }}-config
  namespace: {{ .Release.Namespace }}
spec:
{{- end }}

The unit test for the same is written under _test folder with the file configpvc_test.yaml as follows:

---
suite: test config-pvc
templates:
  - config-pvc.yaml
tests:
  - it: should use local values when deployed as local chart
    set:
      storage.nfs.accessModes: ReadyWriteMany
      storage.nfs.configSize: 10Mi
    asserts:
      - hasDocuments:
          count: 1
      - equal:
          path: spec.accessModes[0]
          value: ReadyWriteMany
      - equal:
          path: spec.resources.requests.storage
          value: 10Mi

  - it: should override name and namespace
    set:
      nameOverride: cms-hello
    release:
      namespace: test
    asserts:
      - hasDocuments:
          count: 1
      - isKind:
          of: PersistentVolumeClaim
      - isAPIVersion:
          of: v1
      - equal:
          path: metadata.namespace
          value: test
      - equal:
          path: metadata.name
          value: cms-hello-config

The result of running the test gives the following image

Issue: The lib chart part is not gettting rendered by the unittest plugin and is reporting as null in the sections where its getting checked for values.

raghav19 avatar Nov 27 '21 13:11 raghav19

It might be an indentation/newline issue on apiVersion: v1, since it's the first element of the document ? I usually do a helm template --debug to check the rendered YAML

rquinio avatar Nov 28 '21 09:11 rquinio

Hi @rquinio , The following is the templated config-pvc.yaml which is getting rendered successfully after doing dependency update. image

I even tried helm install --dry-run... and there are no errors there as well.

raghav19 avatar Nov 29 '21 03:11 raghav19

@quintush , any way to approach this which I might be doing wrong?

raghav19 avatar Dec 16 '21 08:12 raghav19