emutest

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 20 Imported by: ? 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 emutest starts an in-process gcpemu instance for Go tests (FR-CI-009). Every port is allocated dynamically and state is ephemeral.

Index

Constants

View Source
const ClusterOpTimeout = 16 * time.Minute

ClusterOpTimeout is how long tests wait for a GKE cluster operation. It is longer than the emulator's own bring-up waits added up (the k3s admin kubeconfig and the API server, twice when the server exits and is started again, the nodes and the add-ons' CRDs: 13m), with room for image setup, which has no deadline, so a slow bring-up fails with the emulator's error rather than the test's (#396).

View Source
const ClusterSlotsEnv = "GCPEMU_TEST_CLUSTERS"

ClusterSlotsEnv sets how many tests of the user's test binaries may run GKE clusters at once (default 2): every k3s server competes for CPU and disk, and too many on a CI runner crash the API server (#396).

Variables

This section is empty.

Functions

func HoldClusterSlot added in v0.9.0

func HoldClusterSlot(t testing.TB)

HoldClusterSlot waits for one of the cluster slots shared by the user's test binaries (ClusterSlotsEnv), up to the test's deadline, and holds it for the rest of the test. Tests that create GKE clusters call it before starting their emulator, and after t.Parallel, so a paused test holds none. Calling it again in the same test does nothing; a subtest that calls it takes a slot of its own.

func RelayStreams added in v0.6.0

func RelayStreams(t testing.TB, inst *Instance) map[string]int64

RelayStreams returns the VM relay's per-target stream counts (vmrelay.Relay.Streams), or nil when the Instance runs no relay. Tests use it to check that the relay carried a path.

func RequireRelayStream added in v0.6.0

func RequireRelayStream(t testing.TB, inst *Instance, what, key string)

RequireRelayStream fails the test when the Instance runs a VM relay and no stream it carried matches: a target equal to key, or ending in key when key starts with ":" (a port).

func RequireRuntime

func RequireRuntime(t testing.TB)

RequireRuntime skips the test unless a container runtime is available (and GCPEMU_SKIP_CONTAINER_TESTS is unset), and makes a static gcpemu binary available for in-container agents.

Types

type Instance

type Instance struct {
	*instance.Instance
}

Instance is a running test emulator.

func Start

func Start(t testing.TB, svcs []string, opts ...Option) *Instance

Start launches an instance running services (plus dependencies) and stops it when the test ends. Set GCPEMU_TEST_LOG=1 to see emulator logs.

func (*Instance) Endpoint

func (i *Instance) Endpoint(name string) string

Endpoint returns the address (host:port) of a named listener, e.g. "gateway", "gcs", "pubsub".

func (*Instance) GatewayURL

func (i *Instance) GatewayURL() string

GatewayURL returns "http://<gateway>".

func (*Instance) Setenv

func (i *Instance) Setenv(t testing.TB)

Setenv sets every client environment variable the instance advertises for the duration of the test.

type Option

type Option func(*config.Config)

Option customises the configuration before start.

func WithDeterministic

func WithDeterministic() Option

WithDeterministic enables deterministic IDs and the fake clock.

func WithIAMMode

func WithIAMMode(mode string) Option

WithIAMMode sets the IAM enforcement mode.

func WithSQLHostClients added in v0.8.0

func WithSQLHostClients() Option

WithSQLHostClients has Cloud SQL instances with a public IP serve host clients on a loopback address on a VM runtime (ADR 0005), as gcpemu does, for tests that dial the address an instance reports (the Cloud SQL connector, pgx or psql to its PRIMARY IP). Without it they serve none, and the host reaches each instance only on its published port (GCPEMU_SQL_<INSTANCE>). On a host without loopback aliases every instance would serve on 127.0.0.1, so the test then holds a lock shared by the user's test binaries for as long as its emulator runs, and its instances must serve one at a time.

Jump to

Keyboard shortcuts

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