scantest

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package scantest exposes utilities for testing the codescan packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertArrayProperty

func AssertArrayProperty(t *testing.T, schema *oaispec.Schema, typeName, jsonName, format, goName string)

func AssertArrayRef

func AssertArrayRef(t *testing.T, schema *oaispec.Schema, jsonName, goName, fragment string)

func AssertProperty

func AssertProperty(t *testing.T, schema *oaispec.Schema, typeName, jsonName, format, goName string)

func AssertRef

func AssertRef(t *testing.T, schema *oaispec.Schema, jsonName, _, fragment string)

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

func CompareOrDumpJSON(t *testing.T, got any, name string)

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 LoadClassificationPkgsCtx

func LoadClassificationPkgsCtx(t *testing.T) *scanner.ScanCtx

func LoadGo118ClassificationPkgsCtx

func LoadGo118ClassificationPkgsCtx(t *testing.T) *scanner.ScanCtx

func LoadPetstorePkgsCtx

func LoadPetstorePkgsCtx(t testing.TB, enableDebug bool) *scanner.ScanCtx

func ResolveTestKey added in v0.35.0

func ResolveTestKey(t *testing.T, defs map[string]oaispec.Schema, short string) string

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

Jump to

Keyboard shortcuts

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