Documentation
¶
Overview ¶
Package specfixture loads acceptance-criteria fixtures out of a Specter spec so tests are driven by the spec rather than by numbers copied beside it.
Specter counts a criterion covered when a test carries its annotation, not when the test asserts what the criterion says. Nothing in the toolchain checks that a test consumed the criterion's inputs or expected_output, so an annotation on a test that hardcodes its values reports coverage it does not have. This package makes the YAML the input and fails when a supplied field goes unread.
It lives in a non-test file because three packages need it. It has no production callers and imports nothing but the standard library and yaml.
Index ¶
- func Load(t TB, path, wantSpecID string) map[string]Criterion
- func Path(depth int, rel string) string
- type Criterion
- type Fields
- func (f *Fields) AllConsumed()
- func (f *Fields) Bool(k string) bool
- func (f *Fields) EmptyList(k string)
- func (f *Fields) Has(k string) bool
- func (f *Fields) Int(k string) int
- func (f *Fields) IsNull(k string)
- func (f *Fields) IsNullable(k string) bool
- func (f *Fields) List(k string) []any
- func (f *Fields) Map(k string) *Fields
- func (f *Fields) MapList(k string) []*Fields
- func (f *Fields) Num(k string) float64
- func (f *Fields) Raw() map[string]any
- func (f *Fields) Str(k string) string
- func (f *Fields) StrList(k string) []string
- type TB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads a spec file and indexes its criteria by id, failing on a duplicate.
A duplicate id is fatal rather than last-wins: two criteria sharing one id let a single annotation report coverage for unrelated behavior, which is how OW-023's new criteria silently collided with the drift event-bus criteria.
Types ¶
type Criterion ¶
type Criterion struct {
ID string `yaml:"id"`
Description string `yaml:"description"`
Priority string `yaml:"priority"`
Inputs map[string]any `yaml:"inputs"`
ExpectedOutput map[string]any `yaml:"expected_output"`
}
Criterion is one acceptance criterion's executable content.
type Fields ¶
type Fields struct {
// contains filtered or unexported fields
}
Fields wraps one map and records which keys a test read.
func ExpectedOf ¶
func (*Fields) AllConsumed ¶
func (f *Fields) AllConsumed()
AllConsumed fails when the criterion supplies something no assertion read.
Call it only from a test that claims the criterion with an @ac annotation.
func (*Fields) EmptyList ¶
EmptyList requires an actual empty list. null is rejected: accepting it would let `violations: []` become `violations: null` with the test still passing.
func (*Fields) Int ¶
Int reads an integer field, rejecting a fractional value.
Truncating silently would let a spec say 2.5 hosts and a test assert 2, so the fixture and the assertion would disagree with nothing failing.
func (*Fields) IsNull ¶
IsNull asserts an explicit null. A missing key and a null are different claims, so get fails on the former.
func (*Fields) IsNullable ¶
IsNullable reports whether a present key holds null, WITHOUT marking it read.
For a field that is legitimately either a value or null. The caller must still consume it: either IsNull to assert the null, or a typed accessor for the value. Peeking does not count as asserting.
func (*Fields) Map ¶
Map reads a nested mapping and returns it wrapped, so nested fields are tracked too.
func (*Fields) MapList ¶
MapList reads a list of mappings and wraps each, so nested fixture entries are consumption-tracked individually.
func (*Fields) Raw ¶
Raw returns the underlying mapping and marks every key read. For a nested fixture whose shape a caller interprets itself; prefer the typed accessors where the shape is fixed.