Skip to content

testing: helm-unittest's isNotNullOrEmpty passes when the path does not exist #4841

Description

helm-unittest's isNotNullOrEmpty does not fail when the path it checks is missing from the rendered manifest. It fails only when the path exists and holds an empty value. So a test that uses it to say "this key is set" keeps passing after the key is renamed or dropped.

The cause is in the validator. isNotNullOrEmpty is isNullOrEmpty with context.Negative set. In pkg/unittest/validators/is_nullorempty_validator.go at v1.1.2, the version CI installs, the "unknown path" error is returned only when !context.Negative. For the negated form the result is len(actual) == 0 && context.Negative, which is true for a path that resolves to nothing.

Checked locally with v1.1.1 against a ConfigMap template:

asserts:
  - isNotNullOrEmpty:
      path: data.nope   # passes
  - isNotEmpty:
      path: data.nope   # passes
  - isNotNull:
      path: data.nope   # fails

exists also fails on a missing path, as expected.

Three test files here use isNotNullOrEmpty:

  • packages/tests/cozy-lib-tests/tests/tls_cacert_test.yaml, lines 44 and 297
  • packages/apps/clickhouse/tests/backup_api_contract_test.yaml, line 89
  • packages/apps/vpn/tests/vpn_test.yaml, line 24

None of them is vacuous today. I swapped each one for exists and the suites stayed green, so every path is present in the current render. The risk is a future rename that these asserts will not notice.

The fix is to add an exists assert next to each of them. It is probably also worth asking upstream whether the negated form is supposed to accept a missing path.

Activity

  1. added
    kind/bugCategorizes issue or PR as related to a bug
    area/testingIssues or PRs related to testing (e2e, bats, unit tests)
    on Oct 9, 2026
  2. Shxshxnkk1 commented on Oct 10, 2026

    @Shxshxnkk1

    Hi! I'd like to work on this issue as my first open-source contribution. I've reviewed the proposed fix and plan to add exists assertions alongside the existing isNotNullOrEmpty assertions at the identified locations. Is this approach acceptable? I'll run the relevant Helm unit tests before submitting a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/testingIssues or PRs related to testing (e2e, bats, unit tests)kind/bugCategorizes issue or PR as related to a bugtriage/needs-triageIndicates an issue needs triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions