Skip to content

test(examples): controller-level component golden tests#158

Open
sourcehawk wants to merge 2 commits into
mainfrom
feat/example-controller-golden-tests
Open

test(examples): controller-level component golden tests#158
sourcehawk wants to merge 2 commits into
mainfrom
feat/example-controller-golden-tests

Conversation

@sourcehawk

Copy link
Copy Markdown
Owner

Description

Adds controller-level golden.AssertComponentYAML snapshot tests to the
component-prerequisites, extraction-and-guards, and grace-inconsistency
examples. To make this possible, the reconcile logic in each controller is
refactored to extract a Build*Component() method that both the controller
and the tests share — so the golden snapshot reflects the same desired state
that gets reconciled, not a separately-constructed approximation.

Resource tests in those three examples and in custom-resource are also
tightened up to call the real factory functions instead of duplicating the
builder construction inline.

Changes

  • Extract BuildInfraComponent/BuildAppComponent from component-prerequisites controller; same pattern for extraction-and-guards and grace-inconsistency (BuildComponent)
  • Add controller_test.go + testdata/ golden snapshots per example via golden.AssertComponentYAML
  • Update resource tests to call factory functions (NewConfigMapResource, NewDeploymentResource, etc.) rather than re-building primitives inline
  • Simplify custom-resource certificate test to assert registered mutations via concepts.MutationInspector instead of re-running the full mutation logic

Testing

go test ./examples/... and make all (tests + lint + fmt) all pass clean. Golden files were generated with -update and committed alongside the tests.

Copilot AI review requested due to automatic review settings June 25, 2026 14:33

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

Adds controller-level golden snapshot tests for example controllers and refactors controller reconciliation to share component construction with tests, ensuring snapshots reflect the exact desired state that gets reconciled.

Changes:

  • Refactor example controllers to extract shared Build*Component() helpers used by both Reconcile and tests.
  • Add controller-level golden.AssertComponentYAML tests plus committed testdata/*.yaml snapshots for multiple examples.
  • Tighten several resource-level tests to call the real resource factory functions and add mutation/inspection assertions where applicable.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
examples/grace-inconsistency/resources/deployment_test.go Switch resource test to use the deployment factory and snapshot the previewed desired state.
examples/grace-inconsistency/app/testdata/component.yaml Add golden snapshot for the controller-built component output.
examples/grace-inconsistency/app/controller.go Extract BuildComponent to share component assembly between controller and tests.
examples/grace-inconsistency/app/controller_test.go Add controller-level golden component snapshot test.
examples/extraction-and-guards/resources/secret_test.go Update Secret resource snapshot test to use the factory and preview interface.
examples/extraction-and-guards/resources/configmap_test.go Update ConfigMap resource snapshot test to use the factory and shared extracted state wiring.
examples/extraction-and-guards/app/testdata/component.yaml Add golden snapshot for multi-resource component preview output.
examples/extraction-and-guards/app/controller.go Extract BuildComponent to share ordered resource registration and shared-state wiring.
examples/extraction-and-guards/app/controller_test.go Add controller-level golden component snapshot test.
examples/custom-resource/resources/certificate_test.go Add mutation-inspection assertions and keep golden shape snapshot using the real factory.
examples/component-prerequisites/resources/deployment_test.go Update Deployment tests to use the factory, add mutation inspection test, and snapshot per version.
examples/component-prerequisites/resources/configmap_test.go Update ConfigMap resource snapshot test to use the factory and preview interface.
examples/component-prerequisites/app/testdata/infra-component.yaml Add golden snapshot for infra component preview output.
examples/component-prerequisites/app/testdata/app-component.yaml Add golden snapshot for app component preview output.
examples/component-prerequisites/app/controller.go Extract BuildInfraComponent / BuildAppComponent for shared assembly and testability.
examples/component-prerequisites/app/controller_test.go Add controller-level golden component snapshot tests for both infra and app components.

Comment on lines 41 to 42
golden.AssertYAML(t, "testdata/deployment.yaml", res.(golden.Previewer),
golden.WithScheme(testScheme()), golden.Update(*update))
Comment on lines 39 to 40
golden.AssertYAML(t, "testdata/configmap.yaml", res.(golden.Previewer),
golden.WithScheme(scheme), golden.Update(*update))
Comment on lines 26 to 27
golden.AssertYAML(t, "testdata/secret.yaml", res.(golden.Previewer),
golden.WithScheme(scheme), golden.Update(*update))
Comment on lines 37 to 38
golden.AssertYAML(t, "testdata/configmap.yaml", res.(golden.Previewer),
golden.WithScheme(scheme), golden.Update(*update))
Comment on lines +65 to +66
golden.AssertYAML(t, tt.golden, res.(golden.Previewer),
golden.WithScheme(scheme), golden.Update(*update))
require.NoError(t, err)

golden.AssertYAML(t, "testdata/certificate.yaml", res, golden.Update(*update))
golden.AssertYAML(t, "testdata/certificate.yaml", res.(golden.Previewer), golden.Update(*update))
sourcehawk and others added 2 commits June 25, 2026 19:38
Extract Build*Component() methods from the reconcile loops in the
component-prerequisites, extraction-and-guards, and grace-inconsistency
examples so tests can build components through the same assembly path
the controller uses. Add controller_test.go + testdata/ golden snapshots
for each example using golden.AssertComponentYAML.

Update resource tests in all three examples (and custom-resource) to
call the actual factory functions rather than duplicating builder
construction, so the golden files reflect real factory output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Drop the three controller_test.go files added in the previous commit.
main now carries component_test.go in each example's app package that
already provides the same golden.AssertComponentYAML coverage, so the
files were redundant and caused a redeclaration conflict on update and
testOwner when CI merged the branch.

Replace unchecked res.(golden.Previewer) casts in the resource tests
with ok-checked require.True assertions, as flagged in review, so a
non-Previewer resource produces a clear test failure instead of a panic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sourcehawk sourcehawk force-pushed the feat/example-controller-golden-tests branch from abb9b24 to 1042281 Compare June 25, 2026 17:41
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