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

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

Open
raghav19 opened this issue Nov 27, 2021 · 3 comments

Comments

@raghav19
Copy link

raghav19 commented Nov 27, 2021

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.

@rquinio
Copy link

rquinio commented Nov 28, 2021

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

@raghav19
Copy link
Author

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
Copy link
Author

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

d3adb5 pushed a commit to d3adb5/helm-unittest-tests that referenced this issue Apr 30, 2024
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

2 participants