Documentation
¶
Overview ¶
Package fixturetest provides the shared helpers for tests that exercise the backend contract fixtures under openapi/fixtures: loading a fixture, concretizing its placeholder tokens, comparing JSON structurally with null and absent treated as equal, and matching request paths whose variable segments are placeholders.
Both internal/contract (generated-client round-trips) and internal/mcp (tool round-trips through a real MCP session) build on this package, so the two suites agree on what "matches the fixture" means.
Index ¶
- func Canonicalize(raw []byte) (any, error)
- func Concretize(raw json.RawMessage) json.RawMessage
- func ConcretizeString(s string) string
- func Dir(t *testing.T) string
- func LibraryCoords(p string) (account, repo string)
- func PathMatches(fixturePath, actualPath string) bool
- func RepoCoords(p string) (account, repo string)
- func SegmentAfter(p, marker string) string
- type Fixture
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonicalize ¶
Canonicalize decodes JSON into a generic tree with nulls dropped and every number coerced to float64, so a comparison of two canonicalized trees treats (a) an explicit null and an absent key as equal — a nullable field the backend renders null but a generated `omitempty` field drops — and (b) numeric-representation artifacts as equal — JSON has no int/float distinction, so a fixture `1.0` and Go's re-marshaled `1` must compare equal.
func Concretize ¶
func Concretize(raw json.RawMessage) json.RawMessage
Concretize replaces every placeholder token that appears inside JSON string values with its type-valid sample, so typed Go fields can unmarshal it. Placeholders only ever occupy (or are embedded in) JSON strings, so a plain token substitution on the raw JSON text is exact and reversible.
func ConcretizeString ¶
ConcretizeString is Concretize for plain text: it substitutes placeholder tokens in s, for example to turn the "<uuid>" segment of a fixture path into the concrete path parameter a client call needs.
func Dir ¶
Dir returns the absolute path of the shared fixture directory, located relative to this source file so tests pass regardless of working directory.
func LibraryCoords ¶
LibraryCoords pulls the {account, repo} pair out of a "/v1/library/models/{account}/{repo}" fixture path (get_library_model). The repos-based RepoCoords does not apply to the library namespace.
func PathMatches ¶
PathMatches compares a fixture path (whose variable segments are placeholder tokens like "<uuid>") against an actual path segment-by-segment, treating any "<...>" fixture segment as a wildcard.
func RepoCoords ¶
RepoCoords pulls the {account, repo} pair out of a "/v1/repos/{a}/{r}/..." fixture path. The values are placeholder-free literals from the fixtures (stable account/repo names), so they drive the generated path builders.
func SegmentAfter ¶
SegmentAfter returns the path segment immediately following marker in the fixture path (e.g. the model key after "models"), or "" if absent.
Types ¶
type Fixture ¶
Fixture is one shared contract fixture: the request the backend documented for an operation and the exact response its TestClient produced.
type Request ¶
type Request struct {
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
Body json.RawMessage `json:"body"`
}
Request is the documented request half of a fixture. Path may carry placeholder segments (for example "<uuid>") standing in for per-run values.