testutil

package
v1.0.95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil holds test-only helpers shared across event subsystem tests.

Index

Constants

View Source
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

View Source
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

func NewBusStub(rawAck string, rawFrames ...string) *BusStub

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) Dial

func (t *FakeTransport) Dial(_ string) (net.Conn, error)

func (*FakeTransport) DidCleanup

func (t *FakeTransport) DidCleanup() bool

func (*FakeTransport) Listen

func (t *FakeTransport) Listen(_ string) (net.Listener, error)

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL