testenv

package
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testenv wraps controller-runtime's envtest.Environment with helpers common to integration tests that exercise a real kube-apiserver + etcd: lifecycle, kubeconfig file shim, per-test namespace creation.

The package is intentionally seictl-agnostic — pure K8s plumbing. sei-protocol/platform#118 tracks adding envtest to sei-k8s-controller; when that lands, the natural extraction is to a shared sei-protocol/sei-k8s-testkit module that both repos consume.

Requires KUBEBUILDER_ASSETS pointing at a setup-envtest binary directory. Callers without it should set it via `make test-envtest` or the equivalent CI step before invoking `go test`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

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

Env is a started envtest environment. Call Stop in test cleanup.

func Start

func Start(opts ...Option) (*Env, error)

Start spins up an envtest.Environment. Designed for TestMain — callers invoke Stop() themselves before exiting. For per-test bootstrap (rare; prefer one Start per package via TestMain), a separate helper would register t.Cleanup.

Returns an actionable error if KUBEBUILDER_ASSETS is unset; the binary fetch is the harness's job (Makefile / CI), not the test's.

func (*Env) RESTConfig

func (e *Env) RESTConfig() *rest.Config

RESTConfig returns a config pointing at the test apiserver. The returned pointer is owned by envtest; treat it as read-only.

func (*Env) Stop

func (e *Env) Stop() error

Stop tears down the apiserver + etcd. Idempotent on errors.

func (*Env) UniqueNamespace

func (e *Env) UniqueNamespace(t testing.TB, prefix string) string

UniqueNamespace creates a namespace named `<prefix>-<test-id>` and returns its name. No cleanup is registered — Stop() drops the whole apiserver, so per-namespace teardown adds latency for no benefit.

func (*Env) WriteKubeconfig

func (e *Env) WriteKubeconfig(t testing.TB) string

WriteKubeconfig writes a kubeconfig file pointing at the test apiserver into a fresh tempdir and returns its path. Useful for production code paths that take a kubeconfig path string rather than a *rest.Config.

type Option

type Option func(*envtest.Environment)

Option configures the underlying envtest.Environment before Start.

func WithCRDPaths

func WithCRDPaths(paths ...string) Option

WithCRDPaths registers CRD YAML files at the given paths so envtest installs them before tests run.

Jump to

Keyboard shortcuts

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