Documentation
¶
Overview ¶
Package golden provides snapshot testing utilities for verifying resource primitive output across versions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 CompareYAML ¶
CompareYAML calls PreviewObject 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 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.