testenv

package
v0.5.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 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 testenv starts a local API server (envtest) with the Inkwall CRDs installed, for operator tests. The kube-apiserver and etcd binaries come from KUBEBUILDER_ASSETS, which `make test` sets; without it the tests that need the server are skipped.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CRDDir

func CRDDir() string

CRDDir is the directory of the generated CRDs.

func DeleteOnCleanup added in v0.5.0

func DeleteOnCleanup(t testing.TB, c client.Client, objs ...client.Object)

DeleteOnCleanup deletes objs (cluster-scoped ones, say) when t ends, so that the test can run again against the same API server.

func FreeAddr added in v0.5.0

func FreeAddr(t testing.TB) string

FreeAddr returns "127.0.0.1:<port>" for a port a test's server can bind, on every interface, a moment later. The port is below the kernel's ephemeral range, from which every outgoing connection takes its local port: a free port picked inside it can be taken by a connection before the server binds it (#452). No two calls in a process return the same.

func InstallEnvoyGateway added in v0.3.0

func InstallEnvoyGateway(e *Env) error

InstallEnvoyGateway installs stand-ins for Envoy Gateway's CRDs (testenv/envoy-gateway) while the operator runs, and waits until they are served.

func InstallGatewayAPI added in v0.3.0

func InstallGatewayAPI(e *Env) error

InstallGatewayAPI installs stand-ins for Gateway API's GatewayClass, Gateway and HTTPRoute CRDs (testenv/gateway-api) while the operator runs, and waits until they are served.

func InstallIstio added in v0.4.0

func InstallIstio(e *Env) error

InstallIstio installs stand-ins for Istio's EnvoyFilter, VirtualService and Gateway CRDs (testenv/istio) while the operator runs, and waits until they are served.

func InstallLater added in v0.1.1

func InstallLater(e *Env) error

InstallLater installs the CRDs a test adds while the operator runs (testenv/later: Traefik's IngressRoute), and waits until they are served.

func Namespace added in v0.5.0

func Namespace(t testing.TB, c client.Client, prefix string) string

Namespace creates a namespace named prefix and a random suffix, and returns its name. A test that runs again against the same API server (go test -count) gets a new one: envtest has no namespace controller, so a deleted namespace stays Terminating and nothing can be created in it.

func SamplesDir

func SamplesDir() string

SamplesDir is the directory of the sample objects.

func Skip

func Skip(t testing.TB, e *Env)

Skip skips t when there is no API server.

Types

type Env

type Env struct {
	// Config reaches the API server.
	Config *rest.Config
	// WebhookPort is where the API server calls the webhooks, on
	// localhost, when they are installed.
	WebhookPort int
	// contains filtered or unexported fields
}

Env is a running API server.

func Start

func Start(o Options) (*Env, func(), error)

Start starts an API server, typically from TestMain, and returns it and a function that stops it. The Env is nil when KUBEBUILDER_ASSETS is not set; Skip then skips the tests.

func (*Env) User added in v0.1.1

func (e *Env) User(name string, groups ...string) (*rest.Config, error)

User returns a configuration for another user of the API server, in the given groups ("system:masters" may do anything).

type Options

type Options struct {
	// Webhooks installs the operator's webhook configuration, pointed at
	// https://localhost:<WebhookPort>.
	Webhooks bool
}

Options configures Start.

Jump to

Keyboard shortcuts

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