controllertest

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package controllertest provides a small envtest harness that generated `<crd>_controller_test.go` files use in their TestMain setup. The harness exists for two reasons:

  1. envtest binaries (kube-apiserver, etcd) are not available in every developer environment. New(t) returns a non-nil *envtest.Environment when KUBEBUILDER_ASSETS is set or when setup-envtest has installed binaries to the standard cache directory; otherwise it skips the test cleanly via t.Skip.

  2. CRD path resolution is project-specific. The WithCRDs option lets generated tests point at "config/crd/bases" or "deploy/crd/" without re-implementing the join + glob logic.

All public surface is option-shaped so the harness is forward- compatible: adding a new knob is a new option, not a new parameter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(t *testing.T, opts ...Option) *envtest.Environment

New constructs an envtest.Environment configured by opts, or skips the test when envtest binaries are not available.

Availability is detected via:

  • KUBEBUILDER_ASSETS env var (set by `setup-envtest use ...`).
  • The standard envtest cache directory ($HOME/.local/share/kubebuilder-envtest/k8s/<version>).

When neither is available, New calls t.Skip and returns nil. The generated test scaffolds check for nil and bail early.

Types

type Option

type Option func(*envtest.Environment)

Option configures the envtest environment built by New.

func WithCRDs

func WithCRDs(paths ...string) Option

WithCRDs adds CRD YAML directories to the environment's CRDDirectoryPaths. Paths may be relative to the test's working directory.

func WithScheme

func WithScheme(s *runtime.Scheme) Option

WithScheme registers the runtime scheme on the environment. The scheme is consumed by callers via env.Config — controller-runtime builders must AddToScheme themselves; this option is a marker that preserves the scheme alongside the env for callers that want to stash it.

Jump to

Keyboard shortcuts

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