Help us shape the future of Go! Take the 2026 Go Developer Survey

testutil

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package testutil provides shared envtest bootstrap helpers for the operator integration suites under cmd/thv-operator/test-integration. Each suite delegates its BeforeSuite/AfterSuite plumbing here and keeps only its per-suite controller registrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SuiteEnv

type SuiteEnv struct {
	// Cfg is the rest config for the running envtest control plane.
	Cfg *rest.Config
	// Client is a controller-runtime client wired to the global scheme.
	Client client.Client
	// Manager is the controller manager. It is nil for StartMinimalSuite and is
	// created but not started by StartSuite — call StartManager to launch it.
	Manager ctrl.Manager
	// Ctx is the suite-scoped context cancelled by Stop. Specs and indexers that
	// need a context should use it.
	Ctx context.Context
	// contains filtered or unexported fields
}

SuiteEnv holds the shared envtest infrastructure for an operator integration suite. It is produced by StartSuite (full bootstrap with a manager) or StartMinimalSuite (envtest + client only) and torn down by Stop.

func StartMinimalSuite

func StartMinimalSuite() *SuiteEnv

StartMinimalSuite bootstraps an envtest control plane with no operator CRDs and no controller manager: just the API server, the apiextensions scheme (so tests can install CRDs on demand), and a client. It exists for the StorageVersionMigrator suite, which installs its own CRDs per-test and drives reconcilers directly. It must be called from within a Ginkgo node.

func StartSuite

func StartSuite(opts SuiteOptions) *SuiteEnv

StartSuite bootstraps a full operator integration suite: it starts an envtest control plane loaded with the operator CRDs, registers the operator API versions plus the built-in Kubernetes types on the global client-go scheme, creates a client and a controller manager (metrics and health probes disabled), and optionally installs the GroupRef field indexers.

The returned manager is not started — callers register their controllers on it and then call StartManager. Pair every StartSuite with a deferred or AfterSuite call to Stop. It must be called from within a Ginkgo node (BeforeSuite or a spec) because it uses Ginkgo/Gomega for logging and assertions.

func (*SuiteEnv) StartManager

func (e *SuiteEnv) StartManager()

StartManager launches the controller manager in a background goroutine. Call it after registering all controllers on Manager. It is a no-op when there is no manager (i.e. for StartMinimalSuite).

func (*SuiteEnv) Stop

func (e *SuiteEnv) Stop()

Stop cancels the suite context and tears down the envtest control plane. When a manager is running it first waits a short grace period so the manager can shut down cleanly before the API server goes away.

type SuiteOptions

type SuiteOptions struct {
	// RegisterGroupRefIndexers installs the spec.groupRef field indexers for
	// MCPServer, MCPRemoteProxy, and MCPServerEntry. Suites whose controllers
	// list by GroupRef (anything that wires up the MCPGroup or VirtualMCPServer
	// controllers) need these; the rest leave it false.
	RegisterGroupRefIndexers bool
}

SuiteOptions configures the envtest bootstrap performed by StartSuite. Add fields only as concrete suites require them.

Jump to

Keyboard shortcuts

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