Documentation
¶
Overview ¶
Package golden provides snapshot testing utilities for verifying resource primitive output across versions.
Index ¶
- func AssertComponentYAML(t *testing.T, path string, c ComponentPreviewer, opts ...Option)
- func AssertYAML(t *testing.T, path string, p Previewer, opts ...Option)
- func CompareComponentYAML(path string, c ComponentPreviewer, opts ...Option) error
- func CompareYAML(path string, p Previewer, opts ...Option) error
- type ComponentPreviewer
- type MismatchError
- type Option
- type Previewer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertComponentYAML ¶ added in v0.11.0
func AssertComponentYAML(t *testing.T, path string, c ComponentPreviewer, opts ...Option)
AssertComponentYAML is a test helper that calls CompareComponentYAML and fails the test if the result does not match the golden file.
func AssertYAML ¶
AssertYAML is a test helper that calls CompareYAML and fails the test if the result does not match the golden file. See CompareYAML for details.
func CompareComponentYAML ¶ added in v0.11.0
func CompareComponentYAML(path string, c ComponentPreviewer, opts ...Option) error
CompareComponentYAML calls Preview on c, serializes every rendered object into a single multi-document YAML stream (--- separated, in the order Preview returns them), and compares it against the golden file at path. Returns a *MismatchError if they differ, or nil if they match.
When Update is enabled, the golden file is written and comparison is skipped. WithScheme is applied to each object as in CompareYAML. An empty preview produces empty output.
func CompareYAML ¶
CompareYAML calls Preview on p, serializes the result as YAML, and compares it against the golden file at path. Returns a *MismatchError if they differ, or nil if they match.
When Update is enabled, the golden file is written (creating intermediate directories as needed) and comparison is skipped.
Returns an error if the golden file does not exist and Update is not enabled.
Types ¶
type ComponentPreviewer ¶ added in v0.11.0
ComponentPreviewer is satisfied by a built component that can render the desired state of all the resources it would apply. The component package's *Component implements this through its Preview method.
type MismatchError ¶
MismatchError is returned by CompareYAML when the serialized output does not match the golden file. The Diff field contains a unified diff.
func (*MismatchError) Error ¶
func (e *MismatchError) Error() string
type Option ¶
type Option func(*config)
Option configures behavior.
func Update ¶
Update returns an Option that overwrites the golden file with the actual output when enabled. Typically wired to a -update test flag:
var update = flag.Bool("update", false, "update golden files")
golden.AssertYAML(t, "testdata/foo.yaml", res, golden.Update(*update))
func WithScheme ¶
WithScheme returns an Option that sets apiVersion and kind on the serialized object when TypeMeta is not populated. The scheme is used to look up the object's GroupVersionKind.
Without this option, objects that omit TypeMeta cause serialization to fail. Callers must either populate TypeMeta on the object or provide a scheme via WithScheme so apiVersion and kind can be resolved.