fixturetest

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonicalize

func Canonicalize(raw []byte) (any, error)

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

func ConcretizeString(s string) string

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

func Dir(t *testing.T) string

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

func LibraryCoords(p string) (account, repo string)

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

func PathMatches(fixturePath, actualPath string) bool

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

func RepoCoords(p string) (account, repo string)

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

func SegmentAfter(p, marker string) string

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

type Fixture struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

Fixture is one shared contract fixture: the request the backend documented for an operation and the exact response its TestClient produced.

func Load

func Load(t *testing.T, name string) Fixture

Load reads and decodes one fixture by its stem name (without ".json").

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.

type Response

type Response struct {
	Status  int               `json:"status"`
	Headers map[string]string `json:"headers"`
	Body    json.RawMessage   `json:"body"`
}

Response is the recorded response half of a fixture.

Jump to

Keyboard shortcuts

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