quintush / helm-unittest

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

The chart.appVersion is not being applied #172

Closed alvarezfr closed 1 year ago

alvarezfr commented 2 years ago

I think the problem is that the tool is getting the chart version defined in the file Chart.yml instead of my unittest configuration.

I have just installed the plugin with the command helm plugin install https://github.com/quintush/helm-unittest, so it should be updated but I cannot find the flag to see the version.

My config:

suite: Deployment
templates:
  - deployment.yaml
chart:
  version: v1.0.0
  appVersion: 2.0.0

tests:
- it: default
  asserts:
  - hasDocuments:
      count: 1
  - isKind:
      of: Deployment
  - equal:
      path: spec.template.spec
      value:
        affinity:
          podAntiAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app.kubernetes.io/instance: RELEASE-NAME
                    app.kubernetes.io/managed-by: Helm
                    app.kubernetes.io/name: base
                    app.kubernetes.io/version: 2.0.0
                    helm.sh/chart: base-v1.0.0
                topologyKey: failure-domain.beta.kubernetes.io/zone
              weight: 80

The label app.kubernetes.io/version is generated with this _helper:

{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}

When I run the test, it shows this diff (1.3.1 is the appVersion in the Chart.yaml):

                                --- Expected
                                +++ Actual
                                @@ -9,3 +9,3 @@
                                             app.kubernetes.io/name: base
                                -            app.kubernetes.io/version: 2.0.0
                                +            app.kubernetes.io/version: 1.3.1
                                             helm.sh/chart: base-v1.0.0

Thank you!

quintush commented 1 year ago

Hello @alvarezfr,

I will look into it. Did have some tests validating the behavior, but it seems my tests aren't fully covered.

Greetings, @quintush

quintush commented 1 year ago

Hello @alvarezfr,

I have found the issue and fixed it in the next release.

The yaml parsing was not identifying the appVersion text, so it always expected to be empty and so using the appVersion in the chart.

Greetings, @quintush