cutest

package
v1.14.2 Latest Latest
Warning

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

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

Documentation

Overview

Package cutest is the envtest harness for pkg/credentialuse's tests. It is used only by tests, so it may depend on controller-runtime's envtest; the credentialuse package itself must not (§7.1).

envtest is kube-apiserver and etcd only: there is no namespace controller and no garbage collector (§2). Tests play those parts with the helpers here.

Index

Constants

View Source
const Group = "credentialuse.test.krateo.io"

Group is the API group of the test CRDs.

Variables

View Source
var (
	// WidgetGVK is a namespaced test kind, the holder of the tests.
	WidgetGVK = schema.GroupVersionKind{Group: Group, Version: "v1", Kind: "Widget"}
	// WidgetGVR is its resource.
	WidgetGVR = schema.GroupVersionResource{Group: Group, Version: "v1", Resource: "widgets"}
	// TargetGVK is a namespaced test kind that is protected, like core-provider's
	// KubernetesTarget (§9).
	TargetGVK = schema.GroupVersionKind{Group: Group, Version: "v1", Kind: "Target"}
	// TargetGVR is its resource.
	TargetGVR = schema.GroupVersionResource{Group: Group, Version: "v1", Resource: "targets"}
	// SecretGVR is the core Secret resource.
	SecretGVR = schema.GroupVersionResource{Version: "v1", Resource: "secrets"}
)
View Source
var ErrNotYet = errors.New("not yet")

ErrNotYet is a convenience for Eventually's f.

Functions

func CRD

CRD builds a namespaced CRD in Group, served and stored at v1, whose objects take any fields.

func Eventually

func Eventually(t testing.TB, timeout time.Duration, f func() error)

Eventually calls f until it returns nil or timeout passes, and then fails t with f's last error.

func Require

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

Require skips a test that needs envtest when its binaries aren't there, except under CI, where a skip would hide that the test never ran.

Types

type Env

type Env struct {
	Config   *rest.Config
	Scheme   *runtime.Scheme
	Client   client.Client
	Kube     kubernetes.Interface
	Metadata metadata.Interface
	Dynamic  dynamic.Interface
	// contains filtered or unexported fields
}

An Env is a running envtest API server and admin clients for it.

func Start

func Start() (*Env, error)

Start starts envtest with the Widget and Target CRDs. It returns a nil Env and no error when KUBEBUILDER_ASSETS is unset, so that a test binary runs its other tests; Require then fails or skips the tests that need it.

func (*Env) As

func (e *Env) As(user string, groups ...string) *rest.Config

As returns a copy of the admin config that impersonates user, with groups. Every authenticated user is also in system:authenticated.

func (*Env) AsServiceAccount

func (e *Env) AsServiceAccount(namespace, name string) *rest.Config

AsServiceAccount impersonates the service account namespace/name, with the groups the API server gives it.

func (*Env) FinalizeNamespace

func (e *Env) FinalizeNamespace(ctx context.Context, name string) error

FinalizeNamespace plays the namespace controller's last step: it empties the namespace's spec.finalizers through the finalize subresource, then deletes it again so that the API server removes it. The caller has already deleted, or chosen to leave, its content.

func (*Env) Namespace

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

Namespace creates a namespace with a unique name that starts with prefix, and returns its name. It isn't deleted afterwards: envtest has no namespace controller, and the API server is thrown away with the test binary.

func (*Env) Stop

func (e *Env) Stop() error

Stop stops envtest. A nil Env stops nothing.

Jump to

Keyboard shortcuts

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