Documentation
¶
Overview ¶
Package configsource contains test helpers that mock the source Relay loads its environment configuration from: the Relay Auto Config (RAC) SSE stream.
These live in sharedtest/configsource rather than sharedtest itself because they reference the envfactory package, which transitively imports relayenv and streams. Putting them in a subpackage keeps the top-level sharedtest package importable by relayenv and streams without a circular reference (see sharedtest/package_info.go).
Non-test code should never import this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeAutoConfigDeleteEvent ¶
func MakeAutoConfigDeleteEvent(envID config.EnvironmentID, version int) httphelpers.SSEEvent
MakeAutoConfigDeleteEvent creates an SSE event representing a RAC delete for an environment. version must be greater than the last-known version of that environment.
func MakeAutoConfigPatchEvent ¶
func MakeAutoConfigPatchEvent(env envfactory.EnvironmentRep) httphelpers.SSEEvent
MakeAutoConfigPatchEvent creates an SSE event representing a RAC patch for a single environment.
func MakeAutoConfigPutEvent ¶
func MakeAutoConfigPutEvent(envs ...envfactory.EnvironmentRep) httphelpers.SSEEvent
MakeAutoConfigPutEvent creates an SSE event representing a full RAC put, containing all of the given environments.
Types ¶
type RACMock ¶
type RACMock struct {
// URL is the server's base URL. Point Relay's Main.StreamURI here.
URL string
// contains filtered or unexported fields
}
RACMock is a test HTTP server that emits SSE events in the Relay Auto Config protocol format. Tests use it as Relay's config-stream endpoint by pointing Main.StreamURI at its URL.
It is a thin, reusable wrapper over httphelpers.SSEHandler + httptest.Server with automatic cleanup, intended for tests outside package relay that cannot reach that package's unexported autoConfTest helper. Use the MakeAutoConfig*Event builders to construct events.
func NewRACMock ¶
func NewRACMock(t testing.TB, initialEvent *httphelpers.SSEEvent) *RACMock
NewRACMock creates a new RACMock SSE server. If initialEvent is non-nil it is replayed to every new client that connects (use this for the initial put event). Cleanup is registered with t.Cleanup; call Close() explicitly only if you need early teardown.
func NewRACMockWithReconnect ¶
func NewRACMockWithReconnect(t testing.TB, firstEvent, reconnectEvent *httphelpers.SSEEvent) *RACMock
NewRACMockWithReconnect creates a RACMock that serves firstEvent to the first client that connects and reconnectEvent to the next client, modeling a stream that a client restarts and reconnects to. This supports malformed-payload recovery: a rejected patch forces Relay to restart its config stream, and the backend serves a fresh, corrected put on the reconnection.
Send delivers to the first connection; use it to push the event that forces the restart (e.g. the malformed patch). initialEvent replay applies per handler, so the first connection sees firstEvent and the reconnection sees reconnectEvent. Cleanup is registered with t.Cleanup.
func (*RACMock) Close ¶
func (m *RACMock) Close()
Close shuts down the mock server and terminates any open SSE connections.
func (*RACMock) Enqueue ¶
func (m *RACMock) Enqueue(event httphelpers.SSEEvent)
Enqueue queues an event to be delivered to the next client that connects. Use this before Relay has connected to ensure the event is not dropped.
func (*RACMock) Send ¶
func (m *RACMock) Send(event httphelpers.SSEEvent)
Send emits an event to all currently connected clients. Use this after Relay has connected and you want to trigger a live config update.