Documentation
¶
Overview ¶
Package endpointtest provides the endpoint-level scaffolding a test needs to stand a bridge up: an in-memory endpoint.Store and a snapshotter over an empty fleet — and AssertDeviceTypeConformance, which holds a host's assembled topology to its device types.
It is the test-support counterpart of package endpoint, in the shape net/http/httptest has to net/http, and it is separate from bridge/bridgetest for a structural reason rather than a taxonomic one: nothing here refers to the bridge, so the bridge's own white-box tests can import it. A home under bridge/ would import bridge, and an in-package bridge test importing that would close a cycle — which is what left these two fakes stranded in _test.go files, invisible to every consumer, in the first place.
Index ¶
- func AssemblerConfig() endpoint.Config
- func AssertDeviceTypeConformance(tb testing.TB, topology *endpoint.Topology, tolerate ...string) []endpoint.DeviceTypeViolation
- func NewEmptySnapshotter() func(ctx context.Context) (*endpoint.Topology, error)
- type FakeStore
- func (s *FakeStore) GetEndpoint(_ context.Context, key endpoint.SourceKey) (endpoint.Record, error)
- func (s *FakeStore) ListEndpoints(_ context.Context, scope string) ([]endpoint.Record, error)
- func (s *FakeStore) RemoveEndpoint(_ context.Context, key endpoint.SourceKey) error
- func (s *FakeStore) UpsertEndpointAssigning(_ context.Context, rec endpoint.Record) (uint16, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssemblerConfig ¶
AssemblerConfig returns the endpoint.Config NewEmptySnapshotter assembles under.
It is exported for the test that needs a POPULATED fleet, which this package cannot build for it — the device specs are the host's — and which therefore has to construct its own assembler. Sharing the config keeps that assembler's node identity the same as the empty one's, so a reader comparing two topologies sees one identity rather than two, and a consumer's fixtures do not have to guess values that satisfy the assembler's validation.
func AssertDeviceTypeConformance ¶ added in v0.2.0
func AssertDeviceTypeConformance(tb testing.TB, topology *endpoint.Topology, tolerate ...string) []endpoint.DeviceTypeViolation
AssertDeviceTypeConformance fails tb for every device type violation endpoint.ValidateDeviceTypes finds in topology — a host's test that its projection produces endpoints its device types allow, with every mandatory cluster, feature, attribute, command and event in place. Publish the root's and the Aggregator's cluster servers on topology first (endpoint.Endpoint.PublishClusterServers); without them those two endpoints are judged empty.
tolerate lists the violations the host accepts knowingly, each as "<endpoint>/<kind> <requirement>" ("9/instanceCount device:PowerSource", endpoint.DeviceTypeViolation.Key behind the endpoint id). A tolerated entry that matches no violation fails tb too, so the list cannot outlive the reason for it. It returns the violations found, tolerated ones included.
func NewEmptySnapshotter ¶
NewEmptySnapshotter returns a snapshot callback over an empty fleet: one assembler backed by one in-memory store, assembling no device snapshots. The returned func is assignable to bridge.Snapshotter.
It stands in for the composition a host performs at start-up — walk its own device model, assemble a topology, hand the bridge the result. The bridge neither assembles nor knows the host model, so a test that wants a topology has to do what the host does. Only the empty fleet is built here: a populated one needs host device types to project from, which is the host adapter's business.
The assembler and its store are captured once, so endpoint ids persist across repeated calls exactly as they do against a real store.
Types ¶
type FakeStore ¶
type FakeStore struct {
// contains filtered or unexported fields
}
FakeStore is an in-memory implementation of endpoint.Store. It is concurrency-naive — callers must not race it — and carries only the state the bridge's startup and reassembly paths read back.
func NewFakeStore ¶
func NewFakeStore() *FakeStore
NewFakeStore returns a fresh FakeStore with an empty row map and the next-id counter initialised at 2: endpoint 0 is the root and endpoint 1 the aggregator, so bridged endpoints start at 2.
func (*FakeStore) GetEndpoint ¶
GetEndpoint implements endpoint.Store.
func (*FakeStore) ListEndpoints ¶
ListEndpoints implements endpoint.Store. An empty scope matches every row.
func (*FakeStore) RemoveEndpoint ¶
RemoveEndpoint implements endpoint.Store.
func (*FakeStore) UpsertEndpointAssigning ¶
UpsertEndpointAssigning implements endpoint.Store.