testkit

package
v0.14.10 Latest Latest
Warning

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

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

Documentation

Overview

Package testkit provides test helpers for component modules and external plugins: fuzz-target invariants, Go binary builders for fake tools, and lockfile position assertions.

Index

Constants

View Source
const MaxFuzzInputSize = 1 << 20

MaxFuzzInputSize is the shared upper bound for parser fuzz payloads.

Variables

This section is empty.

Functions

func BuildGoBinary

func BuildGoBinary(t testing.TB, outputPath, source string) error

BuildGoBinary writes source to a temporary file and builds it into outputPath.

func BuildGoBinaryFromSource

func BuildGoBinaryFromSource(outputPath, source string) error

BuildGoBinaryFromSource is BuildGoBinary for callers without a testing handle — package TestMain functions that build shared fake binaries once. It manages its own temporary source directory.

func FindDependencyNode added in v0.9.0

func FindDependencyNode(g *model.Graph, label string) (*model.DependencyNode, bool)

FindDependencyNode is FindNode narrowed to a dependency node.

func FindNode added in v0.9.0

func FindNode(g *model.Graph, label string) (model.GraphNode, bool)

FindNode returns the node a "name@version" label names, and whether one matched.

A label matches a node's ID outright, or its name and version in any of the spellings the node answers to: the bare name, the ecosystem-native name, and the display name. A label with no version matches on name alone, which is what a module or manifest label looks like.

func MustDependencyCoords added in v0.6.0

func MustDependencyCoords(t testing.TB, coords model.Coordinates) *model.DependencyNode

MustDependencyCoords constructs a dependency node from coordinates and fails the test when the constructor rejects them. Test-fixture counterpart of model.NewDependencyNode.

func MustDependencyFrom added in v0.9.0

func MustDependencyFrom(t testing.TB, proto model.DependencyNode) *model.DependencyNode

MustDependencyFrom constructs a dependency node from a prototype, copying every field the prototype states, and fails the test when the coordinates cannot mint an identity. Test-fixture counterpart of model.NewDependencyNodeFrom.

func MustDependencyNode added in v0.6.0

func MustDependencyNode(t testing.TB, rawPURL string) *model.DependencyNode

MustDependencyNode constructs a dependency node from a raw package URL and fails the test when the constructor rejects it. Test-fixture counterpart of model.NewDependencyNodeFromPURL for detector, matcher, and plugin tests.

func MustManifestNode added in v0.9.0

func MustManifestNode(t testing.TB, path string, kind model.ManifestKind) *model.ManifestNode

MustManifestNode constructs a manifest node and fails the test when the constructor rejects the path or kind.

func MustModuleNode added in v0.6.0

func MustModuleNode(t testing.TB, manifestPath string, coords model.Coordinates) *model.ModuleNode

MustModuleNode constructs a module node and fails the test when the constructor rejects the path or coordinates. Test-fixture counterpart of model.NewModuleNode.

func NodeID added in v0.9.0

func NodeID(g *model.Graph, label string) string

NodeID returns the ID of the node a label names, or the label unchanged when nothing matches -- so a lookup meant to fail still fails, with the label in the error where a reader expects it.

Use it where a graph method takes an ID rather than returning a node: DirectDependencies, Dependents, CollectPathsTo, AddEdge.

func NodeIs added in v0.9.0

func NodeIs(node model.GraphNode, label string) bool

NodeIs reports whether a node answers to a label: by ID, or by any of the spellings its coordinates carry. It is the comparison form of FindNode, for assertions that hold a node and want to know which one it is.

func RequireFuzzGraphValid

func RequireFuzzGraphValid(t *testing.T, graph *model.Graph)

RequireFuzzGraphValid verifies the minimum invariants of a successfully parsed dependency graph.

func RequireLockfilePositions

func RequireLockfilePositions(t *testing.T, detector plugin.Detector, fixtureDir string, wantPositionKeys []string)

RequireLockfilePositions resolves fixtureDir with the given detector and asserts that every named package in the resolved graph carries at least one non-empty source position (a location whose Position names a file and a 1-based line). It is the per-detector replacement for the Bomly CLI's cross-detector position test: each detector module keeps its own lockfile fixture and asserts its own position extraction with one call.

wantPositionKeys entries are graph node IDs — canonical package URLs such as "pkg:npm/left-pad@1.3.0" (ADR-0041). A missing node or a node without a position fails the test with the offending key.

func SplitNodeLabel added in v0.9.0

func SplitNodeLabel(label string) (name, version string)

SplitNodeLabel splits "name@version" at the last "@", so a scoped npm name ("@scope/pkg@1.2.3") splits where it should.

Types

This section is empty.

Jump to

Keyboard shortcuts

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