Add cluster-free component preview for whole-component golden tests#122
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a public cluster-free preview path so components and resource primitives can render desired-state Kubernetes objects for snapshot/golden testing without running reconciliation or using a client.
Changes:
- Adds
concepts.Previewable,Component.Preview, andComponent.Resource. - Replaces primitive-level typed
PreviewObjectpublic methods withPreview() (client.Object, error). - Adds whole-component golden YAML helpers and updates examples/docs/tests.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/component/component.go |
Adds component preview and resource lookup APIs. |
pkg/component/component_test.go |
Tests component preview and lookup behavior. |
pkg/component/concepts/previewable.go |
Defines the preview capability interface. |
pkg/component/concepts/previewable_test.go |
Verifies previewable interface shape. |
pkg/component/zz_mock_resource_test.go |
Adds a previewable mock resource. |
pkg/generic/resource_base.go |
Adds polymorphic Preview wrapper around PreviewObject. |
pkg/generic/resource_base_test.go |
Tests generic preview behavior and no state mutation. |
pkg/testing/golden/golden.go |
Adds non-generic preview APIs and component YAML comparison. |
pkg/testing/golden/golden_test.go |
Tests component golden output behavior. |
pkg/primitives/*/resource.go |
Updates built-in primitives to expose Preview. |
pkg/primitives/deployment/preview_test.go |
Adds previewable conformance assertion. |
examples/mutations-and-gating/features/*.go |
Updates examples to use Preview with type assertions. |
examples/custom-resource/resources/certificate_test.go |
Updates custom-resource preview test. |
docs/component.md |
Documents component preview and resource lookup. |
docs/guidelines.md |
Documents whole-component golden snapshots. |
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.
Summary
Closes #121.
Adds a public, cluster-free way to render a built
Component's assembled desired-state resources, so consumers can snapshot-test the full resource set the controller actually builds (baseline + mutations + registration order) without a fake client or a reconcile.concepts.Previewable { Preview() (client.Object, error) }, implemented bygeneric.BaseResource(wrapping the existing no-side-effectPreviewObject()engine).Component.Preview() ([]client.Object, error)renders managed reconcile resources in registration order, with no cluster IO. Read-only resources (fetched, not applied) and delete resources (removal markers) are excluded. Errors if a managed resource is not previewable, renders a nil object, or fails to render.Reconcileremains the only IO path.Component.Resource(identity string) (Resource, bool)looks up any registered resource by itsIdentity().pkg/testing/goldengains whole-component helpersCompareComponentYAML/AssertComponentYAMLthat serialize a component's preview into one multi-document (----separated) golden file.Breaking changes (pre-1.0)
PreviewObject() (*Concrete, error)is replaced by a singlePreview() (client.Object, error). Callers needing the concrete type assert on the returnedclient.Object. The typed enginegeneric.BaseResource.PreviewObject()is retained for internal/custom-resource use.goldensingle-resource API is now non-generic:Previewer,CompareYAML,AssertYAMLusePreview()instead of the genericPreviewObject[T]. Existinggolden.AssertYAML(t, path, res, ...)call sites are unchanged.Docs updated in
docs/component.mdanddocs/guidelines.md.Test Plan
make all(lint, format, unit tests) passesgo test ./...— 42 packages, 0 failuresmake build-examplesbuilds; example tests passBaseResource.Previewno-side-effect under a real mutation, golden multi-document match/mismatch/update/empty🤖 Generated with Claude Code