Documentation
¶
Overview ¶
Package testnodes builds graph nodes for tests.
Node identity is minted by a constructor now (ADR-0041), so a fixture can no longer be written as a struct literal with a hand-chosen ID. Every fixture has to go through NewDependencyNode or NewModuleNode and handle the error -- which, repeated across hundreds of table entries, buries what each test is actually about.
These helpers take the fixture shapes the tests already used and route them through the real constructors. They panic rather than returning an error: a fixture whose coordinates cannot mint an identity is a broken test, not a condition under test. Tests that mean to exercise a rejected identity call the SDK constructor directly and assert on the error.
What each helper does NOT own is the rule it applies. Constructing a node belongs to the SDK constructors, and resolving a "name@version" label to a node belongs to bomly-sdk/testkit: a second copy of the label rules is a second answer to "which node is this", and the two drifted the first time they existed side by side. What is left here is the shape the codec's fixtures are written in -- helpers that panic instead of taking a testing.TB, so a table entry stays one expression.
Internal to this module and test-only: the codec's tests came here from the CLI with these fixtures already written against it (bomly-cli ADR-0040). Nothing outside a test file may import it; a fixture that panics on a coordinate the constructor refuses is right for a test and wrong for a scan.
Index ¶
- func Dep(coords model.Coordinates) *model.DependencyNode
- func DepFrom(proto model.DependencyNode) *model.DependencyNode
- func Find(g *model.Graph, label string) (model.GraphNode, bool)
- func FindDep(g *model.Graph, label string) (*model.DependencyNode, bool)
- func ID(g *model.Graph, label string) string
- func Is(node model.GraphNode, label string) bool
- func Manifest(path string, kind model.ManifestKind) *model.ManifestNode
- func Module(manifestPath, name, version string) *model.ModuleNode
- func ModuleFrom(manifestPath string, coords model.Coordinates) *model.ModuleNode
- func Ref(name, version string) *model.DependencyNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dep ¶
func Dep(coords model.Coordinates) *model.DependencyNode
Dep builds a dependency node from coordinates.
func DepFrom ¶
func DepFrom(proto model.DependencyNode) *model.DependencyNode
DepFrom builds a dependency node from a prototype, copying every field the prototype states onto the constructed node.
It exists so a test can keep describing a fixture as one literal. The identity fields are not copied: they are minted from the prototype's coordinates, which is the whole point of the constructor. The field list is the SDK's, so a field added to the model reaches these fixtures with the producers rather than one release later.
func ID ¶
ID returns the node ID a "name@version" label names, or the label unchanged when no node matches -- so a lookup that is 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.
func Is ¶
Is reports whether a node answers to a "name@version" label: by ID, or by any of the spellings its coordinates carry.
It is the comparison form of Find, for the many assertions that hold a node and want to know which one it is. An exact ID still matches exactly, so a case that names a package URL keeps asserting on the package URL.
func Manifest ¶
func Manifest(path string, kind model.ManifestKind) *model.ManifestNode
Manifest builds a manifest node.
func Module ¶
func Module(manifestPath, name, version string) *model.ModuleNode
Module builds a module node -- the scanned project's own artifact -- from the manifest that declares it plus a bare name and version.
func ModuleFrom ¶
func ModuleFrom(manifestPath string, coords model.Coordinates) *model.ModuleNode
ModuleFrom builds a module node from full coordinates.
func Ref ¶
func Ref(name, version string) *model.DependencyNode
Ref builds a dependency node from a bare name and version. Coordinates with no ecosystem mint a pkg:generic identity, which is what these fixtures want: a node that exists and has an ID, with nothing said about where it came from.
Types ¶
This section is empty.