Documentation
¶
Overview ¶
Package testutil provides utilities for golden file testing.
It mirrors Goa's code generation golden testing approach with: - Global -update/-u flags to refresh goldens - Go/JSON aware formatting and normalization - Generated header version normalization (so headers don't cause diffs) - Simple assertion helpers and a fluent API
Index ¶
- Constants
- func Assert(t testing.TB, goldenPath string, got []byte)
- func AssertGo(t testing.TB, goldenPath string, got string)
- func AssertJSON(t testing.TB, goldenPath string, got []byte)
- func AssertString(t testing.TB, goldenPath string, got string)
- func CompareOrUpdateGolden(t *testing.T, actual, golden string)
- type GoldenFile
- func (g *GoldenFile) Compare(actual string, golden string)
- func (g *GoldenFile) CompareBytes(actual []byte, golden string)
- func (g *GoldenFile) CompareContent()
- func (g *GoldenFile) Content(content []byte) *GoldenFile
- func (g *GoldenFile) Exists(golden string) bool
- func (g *GoldenFile) Path(path string) *GoldenFile
- func (g *GoldenFile) SetUpdateMode(update bool)
- func (g *GoldenFile) StringContent(content string) *GoldenFile
Constants ¶
const DefaultBasePath = "testdata/golden"
DefaultBasePath is the default directory for golden files when using NewGoldenFile with an empty base path.
Variables ¶
This section is empty.
Functions ¶
func AssertJSON ¶
AssertJSON pretty-prints and compares JSON content.
func AssertString ¶
AssertString compares string content against a golden file.
func CompareOrUpdateGolden ¶
CompareOrUpdateGolden is a convenience helper for direct string content. It accepts either absolute or relative golden file paths.
Types ¶
type GoldenFile ¶
type GoldenFile struct {
// contains filtered or unexported fields
}
GoldenFile manages golden file comparisons using a fluent API.
func NewGoldenFile ¶
func NewGoldenFile(t testing.TB, basePath string) *GoldenFile
NewGoldenFile creates a new GoldenFile. When basePath is empty, it defaults to DefaultBasePath.
func (*GoldenFile) Compare ¶
func (g *GoldenFile) Compare(actual string, golden string)
Compare provides a legacy API: compare string content with a golden file path.
func (*GoldenFile) CompareBytes ¶
func (g *GoldenFile) CompareBytes(actual []byte, golden string)
CompareBytes is like Compare but for byte slices.
func (*GoldenFile) CompareContent ¶
func (g *GoldenFile) CompareContent()
CompareContent compares the prepared content against the golden file.
func (*GoldenFile) Content ¶
func (g *GoldenFile) Content(content []byte) *GoldenFile
Content sets the comparison content.
func (*GoldenFile) Exists ¶
func (g *GoldenFile) Exists(golden string) bool
Exists reports whether the golden file exists at the given path.
func (*GoldenFile) Path ¶
func (g *GoldenFile) Path(path string) *GoldenFile
Path sets the golden file path (absolute or relative to basePath).
func (*GoldenFile) SetUpdateMode ¶
func (g *GoldenFile) SetUpdateMode(update bool)
SetUpdateMode forces update behavior for this instance (independent of flags).
func (*GoldenFile) StringContent ¶
func (g *GoldenFile) StringContent(content string) *GoldenFile
StringContent sets the comparison content from a string.