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

Refactor unit tests to support unittests v0.4.4 #417

Merged
merged 1 commit into from
May 9, 2024

Conversation

jk464
Copy link
Contributor

@jk464 jk464 commented May 8, 2024

Implements #414

Updated our tests/unit to support newer versions of unittests - for now bumping to v0.4.4 as v0.5.0 has a bug that impacts us (see helm-unittest/helm-unittest#329)*

Changes required:

  • v0.3.0 of unittests adds jsonPath which required updating our path references to use a jq style compatible syntax
@@ -57,55 +57,55 @@ tests:
       # So, we use isNotNull instead.
       # see: https://github.com/quintush/helm-unittest/issues/122
       - isNotNull:
-          path: metadata.labels.[app.kubernetes.io/name]
+          path: metadata.labels["app.kubernetes.io/name"]
       - isNotNull:
  • isNull changed behavior, such that if the path exists but has an "empty" value - the assertion now fails, i.e. the below k8s definition doesn't pass (when it did before), since having empty keys doesn't do anything functionally when applied to k8s, and in my opinion atleast, looks displeasing/confusing - I fixed up the helm templates to not produce empty imagePullSecrets if nothing is being set - fixing the test again.
@@ -38,8 +38,8 @@ spec:
           {{- toYaml .Values.st2auth.annotations | nindent 8 }}
         {{- end }}
     spec:
-      imagePullSecrets:
       {{- if .Values.image.pullSecret }}
+      imagePullSecrets:
       - name: {{ .Values.image.pullSecret }}
       {{- end }}
       initContainers:
...
  • Some assertions have been renamed as of v0.3.1 (including isNull, which seems to have also been when the aforementioned behavior change was introduced), other that the above issue, nothing else behaviorally seems to have changed and the old names still work - however to ensure we're future proofed in-case they are removed (in the docs atleast isNull and isNotNull are mentioned to be "deprecated", I've update the following assertions:
    • isNotNull with exists
    • isNull with notExists
    • isEmpty with isNullOrEmpty
    • isNotEmpty with isNotNullOrEmpty

With those changes, our tests now work on v0.4.4 (and should work on v0.5.x once the previously mentioned bug is fixed)

The pipeline also has been updated to use v0.4.4


  • Note however, testing with the broken test confirms that our tests are otherwise compatible with v0.5.0 so once we have a fixed v0.5.x version we'll be able to bump to that with hopefully no further changes.

@pull-request-size pull-request-size bot added the size/L PR that changes 100-499 lines. Requires some effort to review. label May 8, 2024
@jk464 jk464 requested a review from cognifloyd May 8, 2024 19:19
@jk464 jk464 mentioned this pull request May 8, 2024
Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please update the quintush/helm-unittest references in tests/README.md as well?

And I have one non-blocking nitpick in .github/workflows/unit.yaml.

Everything else looks great! Thank you for picking this up!

@@ -35,7 +35,7 @@ jobs:
# We should periodically check to see if another fork has taken over maintenance,
# as the de-facto "best" fork has changed several times over the years.
run: |
helm plugin install https://github.com/quintush/helm-unittest --version v0.2.11
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.4.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is .git required?

Suggested change
helm plugin install https://github.com/helm-unittest/helm-unittest.git --version v0.4.4
helm plugin install https://github.com/helm-unittest/helm-unittest --version v0.4.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.git doesn't seem to be required (I tested and it works w/o) - but the unittest documentation https://github.com/helm-unittest/helm-unittest/tree/main?tab=readme-ov-file#install has .git in the install command.

Unsure if we want to remove it, or leave it as is since thats the documented install FQDN.

@cognifloyd cognifloyd self-assigned this May 8, 2024
@cognifloyd cognifloyd added this to the v1.2.0 milestone May 8, 2024
@jk464
Copy link
Contributor Author

jk464 commented May 9, 2024

Would you please update the quintush/helm-unittest references in tests/README.md as well?

And I have one non-blocking nitpick in .github/workflows/unit.yaml.

Everything else looks great! Thank you for picking this up!

Documentation updated

@cognifloyd cognifloyd merged commit 496fc58 into StackStorm:master May 9, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/CD size/L PR that changes 100-499 lines. Requires some effort to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants