harness

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeployApp

func DeployApp(t *testing.T, m *Miren, opts AppOptions) string

DeployApp deploys a testdata application, registers cleanup, and waits for it to become ready. It returns the app name.

func GetSandboxID

func GetSandboxID(t *testing.T, m *Miren, appName string) string

GetSandboxID returns the ID of a running sandbox for the given app by parsing the JSON output of `sandbox list --format json`.

func HTTPGet added in v0.6.0

func HTTPGet(m *Miren, hostname, path string) (statusCode int, body string, err error)

HTTPGet makes an HTTP GET request from inside the dev container via curl. The host header is set to the given hostname so ingress routing works, while the actual request goes to localhost:443 over HTTPS (with -k to skip certificate verification). Port 80 redirects to HTTPS, so we connect directly to avoid redirect resolution issues.

func HTTPGetViaPOP added in v0.7.0

func HTTPGetViaPOP(m *Miren, popListenPort, hostname, path string) (statusCode int, body string, err error)

HTTPGetViaPOP makes an HTTPS GET request through a POP's TLS listener. It uses curl --resolve to route the hostname to 127.0.0.1 on the given port.

func Poll

func Poll(t *testing.T, description string, timeout, interval time.Duration, condition func() (done bool, msg string))

Poll repeatedly calls condition until it returns true or the timeout expires. On timeout, it fails the test with the last message from the condition.

func UniqueAppName

func UniqueAppName(t *testing.T, base string) string

UniqueAppName generates a short app name unique to this test and process. The format is bb-<base>-<hash> where hash is 6 hex chars derived from the test name plus a process-unique run ID to avoid collisions across concurrent runs.

func WaitForAddonReady added in v0.7.0

func WaitForAddonReady(t *testing.T, m *Miren, appName, addonName string, timeout time.Duration)

WaitForAddonReady polls `addon list` until the named addon appears for the app.

func WaitForAddonRemoved added in v0.7.0

func WaitForAddonRemoved(t *testing.T, m *Miren, appName, addonName string, timeout time.Duration)

WaitForAddonRemoved polls `addon list` until the named addon no longer appears for the app.

func WaitForAppReady

func WaitForAppReady(t *testing.T, m *Miren, name string, timeout time.Duration)

WaitForAppReady polls `app list --json` until the named app reports healthy.

func WaitForEnvVar added in v0.7.0

func WaitForEnvVar(t *testing.T, m *Miren, appName, key string, timeout time.Duration)

WaitForEnvVar polls `env list` until the given key appears in the app's environment.

func WaitForEnvVarRemoved added in v0.7.0

func WaitForEnvVarRemoved(t *testing.T, m *Miren, appName, key string, timeout time.Duration)

WaitForEnvVarRemoved polls `env list` until the given key no longer appears in the app's environment.

Types

type AppOptions

type AppOptions struct {
	// Name overrides the generated app name. If empty, one is derived from the
	// test name and Testdata value.
	Name string

	// Testdata is the directory name under testdata/ to deploy (e.g. "go-server").
	Testdata string

	// Env is a list of KEY=VALUE pairs to pass via -e flags.
	Env []string

	// ReadyTimeout is how long to wait for the app to become healthy after deploy.
	// Defaults to 2 minutes.
	ReadyTimeout time.Duration
}

AppOptions configures a test app deployment.

type BackgroundProcess added in v0.7.0

type BackgroundProcess struct {
	PID     string
	LogFile string
	// contains filtered or unexported fields
}

BackgroundProcess represents a process running in the dev container.

func (*BackgroundProcess) Logs added in v0.7.0

func (p *BackgroundProcess) Logs() string

Logs returns the contents of the background process log file.

func (*BackgroundProcess) Stop added in v0.7.0

func (p *BackgroundProcess) Stop()

Stop sends SIGTERM to the background process (runs as root since background processes are started as root).

type CloudEnv added in v0.7.0

type CloudEnv struct {
	CloudURL      string // e.g. http://localhost:18080
	PopListenPort string
	PopH3Port     string
	ClusterID     string
	OrgID         string
	CertXID       string
	PopXID        string
	// contains filtered or unexported fields
}

CloudEnv manages a cloud+POP test environment for global router blackbox tests.

func NewCloudEnv added in v0.7.0

func NewCloudEnv(t *testing.T, m *Miren) *CloudEnv

NewCloudEnv builds a full cloud+POP environment for testing the global router. It builds cloud/POP binaries, starts cloud, registers a POP and cluster, starts POP, and restarts the miren server with --labs globalrouter. The environment is torn down via t.Cleanup.

func (*CloudEnv) BindAppHostname added in v0.7.0

func (env *CloudEnv) BindAppHostname(t *testing.T, hostname string)

BindAppHostname adds a POP hostname entry routing the given hostname to the cluster, with the test TLS certificate.

type Cluster

type Cluster struct {
	Mode        Mode
	RepoRoot    string
	TestdataDir string
	MirenBin    string // only used in local mode
}

Cluster holds targeting information for a test run.

func NewCluster

func NewCluster(t *testing.T) *Cluster

NewCluster reads environment variables and returns a configured Cluster. It fails the test if required configuration is missing.

func (*Cluster) IsPeers added in v0.7.0

func (c *Cluster) IsPeers() bool

IsPeers returns true when the cluster is running in distributed peers mode.

type Miren

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

Miren wraps CLI execution against a target cluster.

func NewMiren

func NewMiren(t *testing.T, cluster *Cluster) *Miren

NewMiren creates a CLI runner bound to the given cluster.

func (*Miren) ContainerPath

func (m *Miren) ContainerPath(hostPath string) string

ContainerPath translates a host-side path to a container-internal path. In dev mode, the repo is mounted at /src inside the iso container.

func (*Miren) MustRun

func (m *Miren) MustRun(args ...string) *Result

MustRun executes a miren CLI command and fails the test on non-zero exit.

func (*Miren) PeerExec added in v0.7.0

func (m *Miren) PeerExec(peer string, args ...string) *Result

PeerExec runs a command on a specific iso peer container. This is only meaningful in ModePeers and is used for verification tasks like querying runner-side state or hitting internal HTTP endpoints.

func (*Miren) Run

func (m *Miren) Run(args ...string) *Result

Run executes a miren CLI command and returns the result. In dev mode the command is dispatched through hack/dev-exec.

func (*Miren) RunCmd added in v0.6.0

func (m *Miren) RunCmd(args ...string) *Result

RunCmd executes an arbitrary command (not miren CLI) in the dev container. In local mode it runs the command directly on the host.

func (*Miren) RunCmdAsRoot added in v0.7.0

func (m *Miren) RunCmdAsRoot(args ...string) *Result

RunCmdAsRoot executes a command in the dev container as root.

func (*Miren) RunCmdBackground added in v0.7.0

func (m *Miren) RunCmdBackground(t *testing.T, env map[string]string, args ...string) *BackgroundProcess

RunCmdBackground starts a command in the dev container as a background process using nohup. Output is captured to a log file. The process is killed via t.Cleanup. Must be called in dev mode.

func (*Miren) SetEnv added in v0.8.0

func (m *Miren) SetEnv(key, value string)

SetEnv sets an environment variable that will be injected into subsequent miren CLI and RunCmd invocations inside the dev container.

type Mode

type Mode string

Mode determines how the harness reaches the miren cluster.

const (
	// ModeDev routes commands through hack/dev-exec inside the iso container.
	ModeDev Mode = "dev"

	// ModeLocal calls the miren binary directly on the host.
	ModeLocal Mode = "local"

	// ModePeers routes commands through iso peers exec into the coordinator
	// container. Used for testing distributed runner topologies.
	ModePeers Mode = "peers"
)

type Result

type Result struct {
	ExitCode int
	Stdout   string
	Stderr   string
}

Result captures the output of a CLI invocation.

func (*Result) OutputContains

func (r *Result) OutputContains(s string) bool

OutputContains checks whether stdout or stderr contains the given substring.

func (*Result) RequireContains

func (r *Result) RequireContains(t *testing.T, substr string)

RequireContains fails the test if neither stdout nor stderr contains substr.

func (*Result) RequireExitCode

func (r *Result) RequireExitCode(t *testing.T, code int)

RequireExitCode fails the test if the exit code doesn't match.

func (*Result) RequireSuccess

func (r *Result) RequireSuccess(t *testing.T)

RequireSuccess fails the test if the command did not exit with code 0.

func (*Result) Success

func (r *Result) Success() bool

Success returns true if the command exited with code 0.

Jump to

Keyboard shortcuts

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