quintush / helm-unittest

BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Add comparison with "any" value of a type

raysaik opened this issue · comments

It would be good to have a "any" value comparison which we have in some of the Unit Test frameworks like XUnit. If I want to compare a value (lets say integer) set in the Values.yaml file and compare the output inside my template file to the expected value (e.g: + 10). It should be something like the one below :

Values.yaml

prometheus:
  prometheusRules:
    mythreshold: 5

resource_test.yaml

set:
   prometheus:
     prometheusRules:
            mythreshold: <any>
        

    asserts:
      - matchRegex:
          path: spec.SpecWherethisValueIsUsed
          pattern: "> <any>"

The problem with asserting hardcoded values in the test file is that someone can bypass the unit test failure by setting a hardcoded value in the template instead of reading it from Values.Yaml

Hello @raysaik,

I'm not familiar with the any value in testing frameworks as part of assertions, only within mocks.

What are you trying to validate in the unittest?

The goal of the unittest plugin is to validate the expected behaviour of the template being generated, not if a user or application has set a specific value in the values file.

In your case i would suggest to have two tests, one validating the original value in the values.yaml and the second to validate the overriden value.
The other option is already described by yourselves, by using the matchRegex assertion.

Greetings,
@quintush