Skip to content

test(examples): guard golden.Previewer type assertions - #169

Merged
sourcehawk merged 1 commit into
mainfrom
fix/guard-previewer-casts
Aug 2, 2026
Merged

test(examples): guard golden.Previewer type assertions#169
sourcehawk merged 1 commit into
mainfrom
fix/guard-previewer-casts

Conversation

@sourcehawk

Copy link
Copy Markdown
Owner

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.md and docs/testing.md teach
consumers to write, and the mutation tests sitting in these same files already
guard their concepts.MutationInspector casts, so the examples were
contradicting both the documentation and their own neighbouring code.

Changes

  • Replace the unchecked res.(golden.Previewer) assertion with a
    previewer, ok := form plus require.True(t, ok) in the six example resource
    shape 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.go with its testdata/ snapshots. Once #158
dropped 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 all passes clean (exit 0), covering unit tests, lint, formatting, the
scaffold wrapper tests, and go build ./examples/.... The change is confined to
test 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.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 with previewer, ok := ... plus require.True(t, ok) in six example tests.
  • Keep golden assertions identical aside from using the guarded previewer variable, 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.

@sourcehawk
sourcehawk merged commit ba6b4d2 into main Aug 2, 2026
7 checks passed
@sourcehawk
sourcehawk deleted the fix/guard-previewer-casts branch August 2, 2026 18:23
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.

2 participants