sttcontract

package
v0.76.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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).

Stability: Beta — API-checked; may change with a changelog callout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunContract

func RunContract(t *testing.T, c Case)

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.

Jump to

Keyboard shortcuts

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