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 CollectStreamChunks(t *testing.T, streamer model.Streamer) []model.Chunk
- func CompareOrUpdateGolden(t *testing.T, actual, golden string)
- func RunProviderConformance(t *testing.T, suite ProviderConformanceSuite)
- 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
- type ProviderCapabilityConformance
- type ProviderConformanceCase
- type ProviderConformanceSuite
- type ProviderStreamingConformance
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 CollectStreamChunks ¶
CollectStreamChunks drains a provider-neutral model stream through EOF and fails the test on any other receive error.
func CompareOrUpdateGolden ¶
CompareOrUpdateGolden is a convenience helper for direct string content. It accepts either absolute or relative golden file paths.
func RunProviderConformance ¶
func RunProviderConformance(t *testing.T, suite ProviderConformanceSuite)
RunProviderConformance validates and runs the provider-neutral behavioral matrix. Streaming providers must prove setup and receive errors, event ordering, premature termination, partial cancellation, close 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 ProviderCapabilityConformance ¶
type ProviderCapabilityConformance struct {
Supported ProviderConformanceCase
Unsupported ProviderConformanceCase
}
ProviderCapabilityConformance requires each adapter to prove either the supported behavior or an explicit unsupported contract for one capability. Exactly one case must be set.
type ProviderConformanceCase ¶
ProviderConformanceCase proves one observable model-provider contract.
type ProviderConformanceSuite ¶
type ProviderConformanceSuite struct {
Provider string
OrdinaryProviderError ProviderConformanceCase
RateLimit ProviderConformanceCase
MalformedToolCall ProviderConformanceCase
Cancellation ProviderConformanceCase
StructuredOutputAndToolChoice ProviderConformanceCase
UsageAccounting ProviderConformanceCase
OutputLimited ProviderConformanceCase
MultimodalInput ProviderCapabilityConformance
TypedThinking ProviderCapabilityConformance
ExactTokenCounting ProviderCapabilityConformance
ToolNameRoundTrip ProviderCapabilityConformance
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 raw model.Provider behavior.
type ProviderStreamingConformance ¶
type ProviderStreamingConformance struct {
Unsupported ProviderConformanceCase
SetupError ProviderConformanceCase
ReceiveError ProviderConformanceCase
ReceiveRateLimit ProviderCapabilityConformance
StateMachine ProviderConformanceCase
EarlyEOF ProviderConformanceCase
PartialCancel ProviderConformanceCase
CloseError ProviderConformanceCase
Terminal ProviderConformanceCase
OutputLimited ProviderConformanceCase
}
ProviderStreamingConformance describes either an explicit unsupported streaming contract or the required lifecycle and event-grammar cases for a streaming provider.