dataplanetest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package dataplanetest runs a dataplane for a test, either constructed directly or assembled from the production fx modules, together with the fake upstreams and connections needed to drive it.

Index

Constants

View Source
const (
	// DefaultUpstream is the name [Config] gives the upstream it wires up.
	DefaultUpstream = "workers"
)

Variables

This section is empty.

Functions

func Config

func Config(up *Upstream) *config.Config

Config returns a minimal valid configuration: an ephemeral gateway port and one upstream named DefaultUpstream pointed at up, routed to by default.

func DeadUpstream

func DeadUpstream(t *testing.T) string

DeadUpstream returns a loopback address with nothing behind it, by taking a port from the kernel and immediately giving it back. The window in which something else could claim that port is small enough to live with in a test, and it is the only way to name an address that is guaranteed unreachable now and free later.

func DialUnix

func DialUnix(t *testing.T, path string) *grpc.ClientConn

DialUnix returns a client connection to the unix socket at path, closed when the test ends.

Types

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

Fixture is a running dataplane and the connections needed to drive it. It stops when the test ends.

func Start

func Start(t *testing.T, cfg *config.Config, opts ...Option) *Fixture

Start constructs a dataplane directly, the way the production fx module does, and starts it. Every request is admitted unless WithAuth says otherwise, and no vault is built, so a cfg configuring inbound auth or encryption is rejected rather than silently exercised without them; use StartApp for those.

func StartApp

func StartApp(t *testing.T, cfg *config.Config) *Fixture

StartApp assembles and starts the whole production module graph around cfg, so config-driven collaborators the dataplane cannot build for itself, an inbound authenticator and an encryption vault, come from the same modules production uses. Prefer Start when a test needs neither.

func (*Fixture) Addr

func (f *Fixture) Addr() string

Addr is the address the gateway is accepting on.

func (*Fixture) Client

Client is a WorkflowService client on the gateway connection.

func (*Fixture) Conn added in v0.7.0

func (f *Fixture) Conn() *grpc.ClientConn

Conn is the client connection to the gateway, for a service Fixture.Client does not cover.

func (*Fixture) Context

func (f *Fixture) Context() context.Context

Context returns a context for one request, bounded by a deadline so a call that never completes fails the test rather than hanging it.

func (*Fixture) Gatherer added in v0.7.0

func (f *Fixture) Gatherer() prometheus.Gatherer

Gatherer is the registry every collector in this plane registered with, and the one its /metrics handler serves. A test asserts against it directly because [applyDefaults] binds that handler to an ephemeral port nothing reports.

func (*Fixture) UpstreamConn

func (f *Fixture) UpstreamConn(name string) *grpc.ClientConn

UpstreamConn is a client connection to the named upstream's own unix socket, the path a local worker bypassing the gateway would dial.

type Option added in v0.7.0

type Option func(*options)

Option adjusts what Start builds the dataplane with.

func WithAuth added in v0.7.0

func WithAuth(a auth.Authenticator) Option

WithAuth replaces the authenticator Start would otherwise admit every request with. The gateway runs it from a stream interceptor, on every stream including the ones it serves itself, so it is also how a test wedges the interceptor chain that carries every forwarded request.

type Upstream

type Upstream struct {
	workflowservice.UnimplementedWorkflowServiceServer
	// contains filtered or unexported fields
}

Upstream is a fake Temporal frontend standing in for the service a dataplane forwards to. It records every request and its metadata, answers GetSystemInfo with an empty response, and echoes QueryWorkflow's arguments back as its result.

func NewTLSUpstream

func NewTLSUpstream(t *testing.T) *Upstream

NewTLSUpstream starts a fake frontend over TLS. Its [Upstream.TLSConfig] carries the CA and client identity needed to dial it, which is the only way to exercise credentials that refuse to travel over an insecure transport.

func NewUpstream

func NewUpstream(t *testing.T) *Upstream

NewUpstream starts a fake frontend on a loopback port over plaintext and stops it when the test ends.

func (*Upstream) Addr

func (u *Upstream) Addr() string

Addr is the host:port the fake frontend is accepting on.

func (*Upstream) GetSystemInfo

GetSystemInfo records the call and answers with an empty response. It is the smallest WorkflowService method that needs no namespace argument.

func (*Upstream) Listen added in v0.6.0

func (u *Upstream) Listen() config.ListenConfig

Listen is the client-side configuration needed to dial this upstream. A plaintext fake has to say so explicitly, because a target with no TLS block verifies the peer against the system root pool.

func (*Upstream) Metadata

func (u *Upstream) Metadata() metadata.MD

Metadata is the incoming metadata of the most recent request, or nil before the first one arrives.

func (*Upstream) QueryWorkflow

QueryWorkflow records the call and echoes the query arguments back as the result, so one call exercises both directions of an interceptor that rewrites payloads.

func (*Upstream) Requests

func (u *Upstream) Requests() []proto.Message

Requests returns every request received so far, in arrival order.

Jump to

Keyboard shortcuts

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