Documentation
¶
Overview ¶
Package testutil contains shared scaffolding for Parsec test packages: boot a real Parsec instance with an ephemeral key, wrap it in a Service, and (optionally) expose the composed HTTP surface via httptest.Server.
Everything here uses real implementations — the broker, manager, signer, and verifier are all the production types. The only thing the helpers shortcut is the ceremony of secret generation and goroutine teardown.
Index ¶
- Constants
- func MustParseName(t *testing.T, s string) channels.Name
- func NewBearerTestServer(t *testing.T) (*httptest.Server, *service.Service, string, func())
- func NewMetricsBearerTestServer(t *testing.T, metricsBearer string) (*httptest.Server, func())
- func NewTestParsec(t *testing.T) (*parsec.Parsec, func())
- func NewTestServer(t *testing.T) (*httptest.Server, *service.Service, func())
- func NewTestService(t *testing.T) (*service.Service, func())
- func RingFromSecret(t testing.TB, secret []byte) *auth.KeyRing
Constants ¶
const Version = "test-0.0.0"
Version is the version string stamped into the Service constructed by the helpers. Tests should not depend on the value; assert against this const.
Variables ¶
This section is empty.
Functions ¶
func MustParseName ¶
MustParseName parses s and fails the test if it doesn't validate. Used by surface tests that need a Name value rather than a string.
func NewBearerTestServer ¶
NewBearerTestServer is like NewTestServer but installs the real MgmtValidator. Returns a freshly minted mgmt bearer so the caller can build an authenticated rpc.Client.
func NewMetricsBearerTestServer ¶
NewMetricsBearerTestServer boots a Parsec instance configured with the supplied metrics bearer token, mounts the full HTTP surface, and returns the server + token so tests can confirm /metrics is gated.
The mgmt validator is disabled because /metrics has its own bearer pathway distinct from the JWT keyring.
func NewTestParsec ¶
NewTestParsec boots a Parsec with an ephemeral random secret and a fast sweep interval. It returns the instance and a cleanup that cancels the goroutine and waits for Run to exit.
The returned Parsec is guaranteed to have started its broker — the helper waits briefly so callers can publish immediately.
func NewTestServer ¶
NewTestServer boots a Parsec + Service and mounts the full HTTP surface (websocket / Twirp / SSE / healthz / manifest) on an httptest.Server. Bearer enforcement is disabled — surface tests pass a Bearer header where the server cares, and the validator is nil so tests don't have to mint mgmt tokens.
The cleanup tears down the http server and the parsec goroutine.
func NewTestService ¶
NewTestService is NewTestParsec wrapped in a Service. The cleanup also shuts down the underlying parsec.
Types ¶
This section is empty.