Documentation
¶
Overview ¶
Package testutil holds test-only helpers shared across event subsystem tests.
Index ¶
Constants ¶
const LegacyAck = `{"type":"hello_ack","bus_version":"v1","first_for_key":true}`
LegacyAck is the hello_ack a bus predating canonical metadata sent: no capability list at all.
Variables ¶
var ErrStubUnconfigured = errors.New("testutil.StubAPIClient: no body or err configured")
Functions ¶
func LegacyEventFrame ¶ added in v1.0.85
func LegacyEventFrame(eventType, eventID, sourceTime string, seq uint64, payload json.RawMessage) string
LegacyEventFrame renders the event frame such a bus wrote: the fields that version knew about and nothing else. app_id, tenant_key and observed_at are absent because they did not exist yet.
Types ¶
type BusStub ¶ added in v1.0.85
type BusStub struct {
// contains filtered or unexported fields
}
BusStub speaks just enough of the local bus protocol to drive a real consumer: it answers the status probe, replies to the hello with a caller-supplied ack, and then writes caller-supplied event frames.
The ack and the frames are raw lines on purpose. Reproducing what an older bus put on the wire is the point — building them through the current protocol constructors would encode today's frame shape and prove nothing about compatibility.
func NewBusStub ¶ added in v1.0.85
NewBusStub returns a stub that answers hello with rawAck and then writes rawFrames, in order, to every consumer that attaches.
func (*BusStub) Listen ¶ added in v1.0.85
func (s *BusStub) Listen(t *testing.T, appID string) *FakeTransport
Listen starts the stub and returns the transport a consumer should dial.
The socket lives in a short directory of its own rather than t.TempDir(): that path embeds the test name, and a unix socket path has a low length limit, so a descriptive subtest name would fail the bind.
type FakeTransport ¶
type FakeTransport struct {
// contains filtered or unexported fields
}
FakeTransport delegates to inner with a fixed addr, so tests can use t.TempDir paths.
func NewWrappedFake ¶
func NewWrappedFake(inner transport.IPC, addr string) *FakeTransport
func (*FakeTransport) Address ¶
func (t *FakeTransport) Address(_ string) string
func (*FakeTransport) Cleanup ¶
func (t *FakeTransport) Cleanup(_ string)
func (*FakeTransport) CleanupCount ¶
func (t *FakeTransport) CleanupCount() int
func (*FakeTransport) DidCleanup ¶
func (t *FakeTransport) DidCleanup() bool
type StubAPIClient ¶
type StubAPIClient struct {
Body string
Err error
GotMethod string
GotPath string
GotBody interface{}
Calls int
// contains filtered or unexported fields
}
StubAPIClient records the last call and returns Body or Err.
func (*StubAPIClient) CallAPI ¶
func (s *StubAPIClient) CallAPI(_ context.Context, method, path string, body interface{}) (json.RawMessage, error)