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

testutil

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 22 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

View Source
var ServedAPIVersions = []string{mcpv1beta1.GroupVersion.Version, mcpv1alpha1.GroupVersion.Version}

ServedAPIVersions are the served toolhive.stacklok.dev versions whose CRD schemas carry the same validation rules.

Functions

This section is empty.

Types

type SessionStorageTLSCase added in v0.52.0

type SessionStorageTLSCase struct {
	// Name is a short identifier, unique among the cases, usable in object names.
	Name string
	// SessionStorage is the spec.sessionStorage under test.
	SessionStorage *mcpv1beta1.SessionStorageConfig
	// WantErr is a substring of the admission error, or empty when the object
	// must be accepted.
	WantErr string
}

SessionStorageTLSCase is one admission case for the sessionStorage.tls CEL rules, which MCPServer, MCPRemoteProxy and VirtualMCPServer share.

func SessionStorageTLSCases added in v0.52.0

func SessionStorageTLSCases() []SessionStorageTLSCase

SessionStorageTLSCases returns the sessionStorage.tls admission cases, so every workload kind is checked against the same rules.

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 waits for Manager.Start to return before stopping the control plane. That wait is load-bearing, not politeness: the manager's informers hold long-running watch requests against kube-apiserver, and kube-apiserver's graceful shutdown blocks on draining them. Signalling the API server to stop while watches are still open makes it miss envtest's 20s ControlPlaneStopTimeout, which surfaces as a flaky "timeout waiting for process kube-apiserver to stop" failure in AfterSuite. The suites with fewer specs than Ginkgo procs (MCPTelemetryConfig, MCPGroup) hit it most often: their idle procs cancel the suite context moments after the informers established their watches.

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