unit-testingyamlkubernetes-helm

Testing Helm hook with Helm unittest


YAML to be tested

metadata:
  annotations:
    "helm.sh/hook": pre-upgrade

Unittest

- it: annotations validation
    asserts:
      - equal:
          path: metadata.annotations."helm.sh/hook"
          pattern: pre-upgrade

When running this unittest I get an error: Error: unknown path metadata.annotations."helm.sh/hook"

Is there a possibility to test the values when the key is quoted?


Solution

  • Try to use brackets

    - it: annotations validation
        asserts:
          - equal:
              path: metadata.annotations["helm.sh/hook"]
              pattern: pre-upgrade