Documentation
¶
Overview ¶
Package scantest exposes utilities for testing the codescan packages.
Index ¶
- func AssertArrayProperty(t *testing.T, schema *oaispec.Schema, ...)
- func AssertArrayRef(t *testing.T, schema *oaispec.Schema, jsonName, goName, fragment string)
- func AssertProperty(t *testing.T, schema *oaispec.Schema, ...)
- func AssertRef(t *testing.T, schema *oaispec.Schema, jsonName, _, fragment string)
- func CompareOrDumpJSON(t *testing.T, got any, name string)
- func FixturesDir() string
- func LoadClassificationPkgsCtx(t *testing.T) *scanner.ScanCtx
- func LoadGo118ClassificationPkgsCtx(t *testing.T) *scanner.ScanCtx
- func LoadPetstorePkgsCtx(t testing.TB, enableDebug bool) *scanner.ScanCtx
- func ResolveTestKey(t *testing.T, defs map[string]oaispec.Schema, short string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertArrayProperty ¶
func AssertArrayRef ¶
func AssertProperty ¶
func AssertRef ¶
AssertRef checks that the named property is a $ref to fragment. Accepts both shapes: a bare $ref schema, and the P7/S7 allOf compound where the $ref rides arm[0] (with description and optional override siblings on the parent / arm[1]).
func CompareOrDumpJSON ¶
CompareOrDumpJSON marshals got to stable JSON and either writes it to <repo>/fixtures/integration/golden/<name> (when UPDATE_GOLDEN=1) or asserts that it JSON-equals the stored golden.
This is the regression-testing harness used to detect any behavior change in the go-openapi/spec objects produced by the scanner, compared against a captured baseline.
Golden files are named by content (fixture bundle + object kind + entity), not by test name, so they survive test reshuffling.
func FixturesDir ¶
func FixturesDir() string
FixturesDir returns the absolute path to the repo-level fixtures/ directory, so tests can run from any package depth without fragile relative paths.
func LoadPetstorePkgsCtx ¶
func ResolveTestKey ¶ added in v0.35.0
ResolveTestKey returns the fully-qualified definitions key whose leaf (the segment after the last '/') equals short, so a sub-builder unit test can keep indexing the definitions map by the short Go name:
schema := models[scantest.ResolveTestKey(t, models, "NoModel")]
and can build the expected fully-qualified $ref the same way:
scantest.AssertRef(t, &schema, "pet", "Pet",
"#/definitions/"+scantest.ResolveTestKey(t, models, "pet"))
The schema builder keys the definitions map by the fully-qualified identity ("<pkgpath>/<name>", see scanner.EntityDecl.DefKey); the spec orchestrator's reduce stage later shortens unique leaves back to the bare name, but sub-builder unit tests run WITHOUT that stage. When no definition carries the leaf, short is returned unchanged so absence checks (`_, ok := models[ResolveTestKey(...)]; assert.False(ok)`) still observe a miss. It fails only on a genuinely ambiguous match, which no current unit fixture produces. See .claude/plans/name-identity-cyclic-ref.md §12.1.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mocks contains mock types for all interfaces.
|
Package mocks contains mock types for all interfaces. |