testutil

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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 Assert

func Assert(t testing.TB, goldenPath string, got []byte)

Assert compares byte content against a golden file.

func AssertGo

func AssertGo(t testing.TB, goldenPath string, got string)

AssertGo formats and compares Go source code.

func AssertJSON

func AssertJSON(t testing.TB, goldenPath string, got []byte)

AssertJSON pretty-prints and compares JSON content.

func AssertString

func AssertString(t testing.TB, goldenPath string, got string)

AssertString compares string content against a golden file.

func CollectStreamChunks added in v1.3.0

func CollectStreamChunks(t *testing.T, streamer model.Streamer) []model.Chunk

CollectStreamChunks drains a provider-neutral model stream through EOF and fails the test on any other receive error.

func CompareOrUpdateGolden

func CompareOrUpdateGolden(t *testing.T, actual, golden string)

CompareOrUpdateGolden is a convenience helper for direct string content. It accepts either absolute or relative golden file paths.

func RunProviderConformance added in v1.3.0

func RunProviderConformance(t *testing.T, suite ProviderConformanceSuite)

RunProviderConformance validates and runs the provider-neutral behavioral matrix. Streaming providers must prove setup errors, receive errors, and successful terminal behavior; adapters without streaming must prove their explicit unsupported result.

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.

type ProviderConformanceCase added in v1.3.0

type ProviderConformanceCase func(t *testing.T)

ProviderConformanceCase proves one observable model-provider contract.

type ProviderConformanceSuite added in v1.3.0

type ProviderConformanceSuite struct {
	Provider                      string
	OrdinaryProviderError         ProviderConformanceCase
	RateLimit                     ProviderConformanceCase
	MalformedToolCall             ProviderConformanceCase
	Cancellation                  ProviderConformanceCase
	StructuredOutputAndToolChoice ProviderConformanceCase
	UsageAccounting               ProviderConformanceCase
	Streaming                     ProviderStreamingConformance
}

ProviderConformanceSuite is the minimum behavioral matrix every model adapter must execute. Provider-specific SDK fixtures stay in the owning package; this suite standardizes only externally observable model.Client behavior.

type ProviderStreamingConformance added in v1.3.0

type ProviderStreamingConformance struct {
	Unsupported  ProviderConformanceCase
	SetupError   ProviderConformanceCase
	ReceiveError ProviderConformanceCase
	Terminal     ProviderConformanceCase
}

ProviderStreamingConformance describes either an explicit unsupported streaming contract or the three required lifecycle cases for a streaming provider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL