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

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

Open
raysaik opened this issue Jan 12, 2023 · 1 comment
Open

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

raysaik opened this issue Jan 12, 2023 · 1 comment

Comments

@raysaik
Copy link

raysaik commented Jan 12, 2023

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

@quintush
Copy link
Owner

quintush commented Feb 3, 2023

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

d3adb5 pushed a commit to d3adb5/helm-unittest-tests that referenced this issue Apr 30, 2024
…Document

Correct failed_template to also work when empty documents are found.
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