Documentation
¶
Overview ¶
Package codectest provides a shared contract suite for es.TypedCodec implementations, mirroring the role eventstoretest plays for event stores (ADR-0018). A codec package opts in with a single call:
func TestContract(t *testing.T) {
codectest.RunContract(t, jsoncodec.For[Order], "order.placed",
Order{ID: "o-1", Total: 99},
func(a, b Order) bool { return reflect.DeepEqual(a, b) })
}
The suite asserts only the behavior every codec must share regardless of wire format: a stable, non-empty content type; round-trip fidelity; statelessness across instances; integration through es.Register and the es.Registry; and rejection of payloads whose dynamic type does not match the registered one. Format-specific concerns — struct-tag handling, wire layout, what counts as malformed input — belong in the codec package's own tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunContract ¶
func RunContract[E any](t *testing.T, newCodec Factory[E], eventType string, sample E, equal func(a, b E) bool)
RunContract runs the codec contract against newCodec. eventType is the name to register under; sample is a representative non-zero value of E; equal reports whether two values of E are equivalent (E is often not comparable with ==, and proto messages must be compared with proto.Equal, so the caller supplies this).
Types ¶
type Factory ¶
type Factory[E any] func() es.TypedCodec[E]
Factory constructs a fresh codec for event type E. A codec package's generic For[E] constructor satisfies it directly, so callers pass it unadorned: codectest.RunContract(t, jsoncodec.For[Order], ...).