testutil

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 13 Imported by: 0

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

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

func MustParseName(t *testing.T, s string) channels.Name

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

func NewBearerTestServer(t *testing.T) (*httptest.Server, *service.Service, string, func())

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

func NewMetricsBearerTestServer(t *testing.T, metricsBearer string) (*httptest.Server, func())

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

func NewTestParsec(t *testing.T) (*parsec.Parsec, func())

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

func NewTestServer(t *testing.T) (*httptest.Server, *service.Service, func())

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 NewTestServerWithRevocations added in v0.3.0

func NewTestServerWithRevocations(t *testing.T) (*httptest.Server, *service.Service, *tokenbroker.MemoryRevocations, func())

NewTestServerWithRevocations is NewTestServer plus a memory-backed tokenbroker.RevocationStore wired through parsec.Options. The store is returned so tests can inspect it directly (e.g. confirm a CLI RevokeToken call landed an entry).

func NewTestService

func NewTestService(t *testing.T) (*service.Service, func())

NewTestService is NewTestParsec wrapped in a Service. The cleanup also shuts down the underlying parsec.

func RingFromSecret

func RingFromSecret(t testing.TB, secret []byte) *auth.KeyRing

RingFromSecret wraps secret in a single-key KeyRing — the standard shape tests use when they need a stable HMAC across a parsec.New / recreate pair.

Types

This section is empty.

Jump to

Keyboard shortcuts

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