Documentation
¶
Overview ¶
Package sttcontract provides a reusable conformance suite that every stt.STTProvider implementation is expected to satisfy.
Provider tests historically re-derived the same invariants (stable identity, provider-stamped results, HTTP-error propagation, context cancellation) by hand, which let subtle drift creep in — e.g. a provider that forgot to stamp Result.Provider, or one that swallowed a 5xx. This package centralises those invariants so a provider's test only has to supply a constructor and a success-response handler, then call RunContract.
The harness is deliberately transport-agnostic: each Case owns the wire format of its own success response via the Success handler, and the harness only asserts behaviour that must hold across every provider.
It lives in a non-test package (rather than a _test.go helper) so it can be shared across provider packages. Provider conformance tests must live in an external test package (e.g. `package stt_test`) to avoid the import cycle that would otherwise form (sttcontract imports stt).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunContract ¶
RunContract executes the full STT conformance suite for c. It fails the test if the case is under-specified, then runs the identity, success, server-error, and context-cancellation invariants as subtests.
Types ¶
type Case ¶
type Case struct {
// Name is a short label used to namespace the subtests (e.g. "vps").
Name string
// ExpectedName is the stable identifier the provider must return from
// Name() and stamp onto Result.Provider for a successful transcription.
ExpectedName string
// WantText is the transcription text that Success yields, decoded through
// the provider's own response parsing.
WantText string
// NewProvider builds the provider bound to baseURL, which is an httptest
// server URL. The provider must be configured to accept that loopback URL
// (relaxed netsec validation) so the success and error paths are exercised
// without real network access.
NewProvider func(baseURL string) stt.STTProvider
// Success serves exactly one successful transcription response in the
// provider's wire format such that the provider parses WantText out of it.
Success http.HandlerFunc
}
Case describes a single STT provider under conformance test.