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 values and snapshot testing issue #19257

Closed
begemotik opened this issue Jun 6, 2023 · 3 comments · Fixed by #19263
Closed

Helm Unittest values and snapshot testing issue #19257

begemotik opened this issue Jun 6, 2023 · 3 comments · Fixed by #19263
Labels
backend: Helm Helm backend-related issues bug

Comments

@begemotik
Copy link

begemotik commented Jun 6, 2023

Describe the bug
Helm unittesting doesn't work if values section is present in *_test.yaml instead of set.

Another point is that if snapshotting testing is used it seems that snapshots in __snapshot__/ directory are ignored and any changes to tests or values in set section doesn't affect the tests run - it's still successful.

Pants version
2.15.1

OS
both

Additional info

  1. Consider the following setup
# deployment_test.yaml
tests:
  - it: checks correct number of replicas
    asserts:
      - equal:
          path: spec.replicas
          value: 2
    values:
      - general_values.yaml
    # IF COMMENT `values` section and uncomment `set` - it works fine.
    # set:
    #   replicaCount: 2

# BUILD
helm_unittest_tests(
  sources=[
    "*_test.yaml",
    "general_values.yaml"
  ]
)

# general_values.yaml

replicaCount: 2

serviceAccount:
  name: opa

The error occurs:

pants test ::
13:07:38.10 [INFO] Completed: Running Helm unittest suite awesome/tests/deployment_test.yaml
13:07:38.11 [ERROR] Completed: Run Helm Unittest - awesome/tests/deployment_test.yaml - failed (exit code 1).

### Chart [ awesome ] awesome

FAIL  test deployment  awesome/tests/deployment_test.yaml
      - checks correct number of replicas
              Error: open awesome/tests/general_values.yaml: no such file or directory
  1. Snapshot testing is also behaves not as expected. So, according to the documentation you need to generate .snap file and put it into __snapshot__ directory. When test runs it compares the output value with the snapshot. While the manifest is generated during the run it doesn't seem to actually compare the result with the snapshot, because any changes to either to snapshot or to values in set section doesn't doesn't impact test results - it's always successful.

Might be related - #16532


I believe both cases are might be related to the same issue and it's related to missing logic on how unittests are integrated into pants. Though I might missing some piece of documentation as well, in that case would appreciate any help :)

@alonsodomin
Copy link
Contributor

Thanks for the report, as you have already found out, Helm snapshot testing is not yet supported.

Regarding the usage of additional value files in tests: this is already possible but the elements used in the BUILD files are slightly different.

The helm_unittest_tests target is meant to be used only to identify test suites or, in other words, _test.yml files only. If you change your BUILD file to be look like the following one, it should work:

helm_unittest_tests(dependencies=[":values"])

resources(name="values", sources=["general-values.yaml"])

Maybe this needs to be improved in the documentation too.

@begemotik
Copy link
Author

begemotik commented Jun 7, 2023

@alonsodomin thank you for responding. Tested the examples you provided and confirm that it works!

As for snapshot testing, as I understand the feature waits for implementation of the common approach, right?

@alonsodomin alonsodomin added the backend: Helm Helm backend-related issues label Jun 7, 2023
@alonsodomin
Copy link
Contributor

That's right, may be able to allocate some time this or next week to look into that common approach.

PS: We'll update the docs regarding the usage of additional files plus add support for providing files via other targets in future releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Helm Helm backend-related issues bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants