Documentation
¶
Overview ¶
Package testutil provides reflection-based helpers used by drift-detection tests in the operator. It is intended for test code only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertNoDrift ¶
AssertNoDrift runs three subtests against spec:
- CRDFieldsCovered: every CRD leaf is mapped or ignored
- RuntimeFieldsCovered: every runtime leaf is mapped or ignored
- MappingTableSanity: tables have no duplicates, empty entries, cross-pollination, or stale leaves
Type parameter ordering is [Runtime, CRD] mirroring how a converter reads: it produces Runtime from CRD. Failure messages reference both type names so a developer who hits a failure can grep directly to the offending field.
testutil.AssertNoDrift[telemetry.Config, v1beta1.MCPTelemetryConfigSpec](
t,
testutil.DriftSpec{
Domain: "telemetry",
Mappings: telemetryFieldMappings,
IgnoredOnCRDOnly: telemetryIgnoredOnCRDOnly,
IgnoredOnRuntimeOnly: telemetryIgnoredOnRuntimeOnly,
},
)
func FlattenJSONLeafFields ¶
FlattenJSONLeafFields returns every leaf JSON field path under t as a sorted slice of dot-delimited paths (e.g. "openTelemetry.tracing.enabled").
A leaf is any type that does not produce nested JSON keys at runtime: a primitive, a slice/map of primitives, or a type implementing json.Marshaler (whose MarshalJSON shape is opaque to reflection). Structs, slices/maps of structs, and pointers to either are recursed into. Field names follow encoding/json rules including `,inline` and anonymous-field promotion. Self-referential types stop on revisit so the walk always terminates.
If t is nil or, after dereferencing, is not a struct, an empty slice is returned rather than panicking.
Types ¶
type DriftSpec ¶
type DriftSpec struct {
Domain string
Mappings []FieldMapping
IgnoredOnCRDOnly map[string]string
IgnoredOnRuntimeOnly map[string]string
}
DriftSpec declares the bidirectional mapping between a CRD spec type and its runtime config counterpart. Every leaf path on either type must be classified into exactly one of three buckets: a Mappings entry, an IgnoredOnCRDOnly entry (with justification), or an IgnoredOnRuntimeOnly entry (with justification). AssertNoDrift fails the test when a leaf is unclassified, when a table entry is stale, or when the tables contradict themselves.
Domain is used in failure messages and subtest names; pick something that matches the domain folder (e.g. "telemetry", "oidc", "vmcp").
type FieldMapping ¶
FieldMapping pairs a CRD-side leaf path with a runtime-side leaf path. Both sides must be present unless the field is in one of the ignore maps of the enclosing DriftSpec.