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

Feat/add snapshot based testing for helm #1378

Merged

Conversation

jguionnet
Copy link
Contributor

@jguionnet jguionnet commented Dec 2, 2023

Description

Fixes #1377

Add a set of helper functions, like the UnmarshalK8SYaml functions.

  • UpdateSnapshot creates/refreshes a local snapshot
  • DiffAgainstSnapshot diffs the manifest generated by the test against the local snapshot. It returns the number of differences that can be asserted in a test. It also displays the difference between the two sets of k8s manifests in git style.

See test output in this gist https://gist.github.com/jguionnet/376e768009a244d3315f31b82598aa78

TODOs

Read the Gruntwork contribution guidelines.

  • [ x] Update the docs. (ie provided sample tests as documentation)
  • [ x] Run the relevant tests successfully, including pre-commit checks.
  • [ x ] Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • [ x ] Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added / Removed / Updated [X].

Added support in Helm for snapshot testing, similar to helm-unittest feature snapshot testing.

Migration Guide

NA

@denis256
Copy link
Member

denis256 commented Dec 4, 2023

This branch has conflicts that must be resolved
Use the [web editor](https://github.com/gruntwork-io/terratest/pull/1378/conflicts) or the  to resolve conflicts.
Conflicting files
go.mod

@jguionnet
Copy link
Contributor Author

@denis256: I resolved the conflict, could you please review it?

modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template_test.go Outdated Show resolved Hide resolved
@jguionnet
Copy link
Contributor Author

@denis256. Thanks for reviewing. I fixed it according to the feedback.

Copy link
Member

@denis256 denis256 left a comment

Choose a reason for hiding this comment

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

Proposed functions don't follow existing patterns:

  • no *E function which check for errors
  • t testing.TestingT not passed

Go mod don't have all changes commited

$ git status
On branch feat/add-remote-repo-support-in-helm
nothing to commit, working tree clean
$ go mod tidy
$ git status
On branch feat/add-remote-repo-support-in-helm
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   go.mod


modules/helm/template.go Outdated Show resolved Hide resolved

reportWriter.WriteReport(os.Stdout)

// return the number of diffs to use in in assertion while testing: 0 = no differences
Copy link
Member

Choose a reason for hiding this comment

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

in

modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
Added an option for snaphsot directory
go mod tidy
Copy link
Member

@denis256 denis256 left a comment

Choose a reason for hiding this comment

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

Approach looks fine, some wording updates and comments on functions should be updated

modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
modules/helm/template.go Outdated Show resolved Hide resolved
@jguionnet
Copy link
Contributor Author

@denis256. Thank you for your thorough review and for catching all my mistakes. I fixed it according to your latest feedback.

@denis256 denis256 merged commit 28c0f43 into gruntwork-io:master Jan 8, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

Add support for snapshot testing
2 participants