test(examples): guard golden.Previewer type assertions - #169
Merged
Conversation
The resource shape tests asserted res.(golden.Previewer) unchecked, so a resource that stopped implementing Previewer would panic instead of failing the assertion. The mutation tests in these same files already guard their concepts.MutationInspector casts, and docs/getting-started.md and docs/testing.md both document the guarded form, so the unchecked casts were the odd ones out. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens the example “resource shape” golden snapshot tests by guarding golden.Previewer type assertions, ensuring failures produce readable assertion output instead of panicking. This aligns the examples with the guidance in docs/testing.md and matches the existing guarded-cast style used elsewhere in the examples.
Changes:
- Replace unchecked
res.(golden.Previewer)assertions withpreviewer, ok := ...plusrequire.True(t, ok)in six example tests. - Keep golden assertions identical aside from using the guarded
previewervariable, so golden behavior/output remains unchanged.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| examples/grace-inconsistency/resources/deployment_test.go | Guard golden.Previewer assertion before calling golden.AssertYAML. |
| examples/extraction-and-guards/resources/secret_test.go | Guard golden.Previewer assertion before calling golden.AssertYAML. |
| examples/extraction-and-guards/resources/configmap_test.go | Guard golden.Previewer assertion before calling golden.AssertYAML. |
| examples/custom-resource/resources/certificate_test.go | Guard golden.Previewer assertion before calling golden.AssertYAML. |
| examples/component-prerequisites/resources/deployment_test.go | Guard golden.Previewer assertion in table-driven test before calling golden.AssertYAML. |
| examples/component-prerequisites/resources/configmap_test.go | Guard golden.Previewer assertion before calling golden.AssertYAML. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The resource shape tests across the examples asserted
res.(golden.Previewer)without checking the result. If a resource ever stopped satisfying
Previewer,those tests would panic rather than fail with a readable assertion. The guarded
form is already what
docs/getting-started.mdanddocs/testing.mdteachconsumers to write, and the mutation tests sitting in these same files already
guard their
concepts.MutationInspectorcasts, so the examples werecontradicting both the documentation and their own neighbouring code.
Changes
res.(golden.Previewer)assertion with apreviewer, ok :=form plusrequire.True(t, ok)in the six example resourceshape tests
Related
Supersedes #158. That PR set out to add controller-level component golden tests,
but that work has since landed on main independently as
examples/*/app/component_test.gowith itstestdata/snapshots. Once #158dropped its now-duplicate controller tests, this cast guarding was the only
change it still carried, so it is being landed here against current main instead
of rebasing a branch whose two commits partly undo each other.
Testing
make allpasses clean (exit 0), covering unit tests, lint, formatting, thescaffold wrapper tests, and
go build ./examples/.... The change is confined totest files; no example or framework behaviour moves. The six affected shape tests
still pass and their golden files are untouched, which confirms the assertions
are running against the same previewers as before rather than being skipped.