testing

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: Apache-2.0 Imports: 53 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeControlledBy added in v0.16.0

func BeControlledBy(expectedOwner any) types.GomegaMatcher

BeControlledBy returns a matcher that checks if a Kubernetes object is owned AND controlled by the specified owner

func BeOwnedBy added in v0.16.0

func BeOwnedBy(expectedOwner any) types.GomegaMatcher

BeOwnedBy returns a matcher that checks if a Kubernetes object is owned by the specified owner

func BeSematicEqual added in v0.1.0

func BeSematicEqual(expected interface{}) types.GomegaMatcher

func HaveBackendRefs added in v0.16.0

func HaveBackendRefs(backends ...gwapiv1.HTTPBackendRef) types.GomegaMatcher

HaveBackendRefs returns a matcher that checks if an HTTPRoute has the specified backend refs.

func HaveCondition added in v0.16.0

func HaveCondition(conditionType string, expectedStatus string) types.GomegaMatcher

HaveCondition returns a matcher that checks if a Status has a condition with the specified type and status

func HaveContainerImage added in v0.16.0

func HaveContainerImage(expectedImage string) types.GomegaMatcher

HaveContainerImage returns a matcher that checks if a Deployment has a container with the specified image

func HaveGatewayRefs added in v0.16.0

func HaveGatewayRefs(expectedGateways ...gwapiv1.ParentReference) types.GomegaMatcher

HaveGatewayRefs returns a matcher that checks if an HTTPRoute has the specified gateway parent refs

func NewTestLogger added in v0.16.0

func NewTestLogger(t testingT) logr.Logger

NewTestLogger returns a logr.Logger that prints to the given testing.T. This is useful for logging in tests, as the output will be buffered and printed only if the test fails.

func ProjectRoot added in v0.16.0

func ProjectRoot() string

ProjectRoot returns the root directory of the project by searching for the go.mod file up from where it is called.

func SetupEnvTest

func SetupEnvTest(crdDirectoryPaths []string) *envtest.Environment

Types

type AddToSchemeFunc added in v0.16.0

type AddToSchemeFunc func(scheme *runtime.Scheme) error

type BeSematicEqualMatcher added in v0.1.0

type BeSematicEqualMatcher struct {
	Expected interface{}
}

func (*BeSematicEqualMatcher) FailureMessage added in v0.1.0

func (matcher *BeSematicEqualMatcher) FailureMessage(actual interface{}) (message string)

func (*BeSematicEqualMatcher) Match added in v0.1.0

func (matcher *BeSematicEqualMatcher) Match(actual interface{}) (success bool, err error)

func (*BeSematicEqualMatcher) NegatedFailureMessage added in v0.1.0

func (matcher *BeSematicEqualMatcher) NegatedFailureMessage(actual interface{}) (message string)

type Cleaner added in v0.16.0

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

Cleaner is a struct to perform deletion of resources, enforcing removal of finalizers. Otherwise, deletion of namespaces wouldn't be possible. See: https://book.kubebuilder.io/reference/envtest.html#namespace-usage-limitation Based on https://github.com/kubernetes-sigs/controller-runtime/issues/880#issuecomment-749742403

func CreateCleaner added in v0.16.0

func CreateCleaner(k8sClient client.Client, config *rest.Config, timeout, interval time.Duration) *Cleaner

func (*Cleaner) DeleteAll added in v0.16.0

func (c *Cleaner) DeleteAll(objects ...client.Object)

type Client added in v0.16.0

type Client struct {
	client.Client
	*envtest.Environment
	*Cleaner
}

Client acts as a facade for setting up k8s envtest. It allows to wire controllers under tests through a simple builder funcs and configure underlying test environment through Option functions. It's composed of k8s client.Client and Cleaner to provide unified way of manipulating resources it the env test cluster.

func (*Client) UsingExistingCluster added in v0.16.0

func (c *Client) UsingExistingCluster() bool

type Config added in v0.16.0

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

func Configure added in v0.16.0

func Configure(options ...Option) *Config

Configure creates a new configuration for the Kubernetes EnvTest.

func NewEnvTest added in v0.16.0

func NewEnvTest(options ...Option) *Config

NewEnvTest prepares k8s EnvTest with prereq

func (*Config) Start added in v0.16.0

func (e *Config) Start(ctx context.Context) *Client

Start wires controller-runtime manager with controllers which are subject of the tests and starts Kubernetes EnvTest to verify their behavior.

func (*Config) WithControllers added in v0.16.0

func (e *Config) WithControllers(setupFunc ...SetupFunc) *Config

WithControllers register controllers under tests required for the test suite.

func (*Config) WithWebhooks added in v0.16.0

func (e *Config) WithWebhooks(setupFunc ...SetupFunc) *Config

WithWebhooks register webhooks under tests required for the test suite.

type Option added in v0.16.0

type Option func(target *envtest.Environment)

func WithCRDs added in v0.16.0

func WithCRDs(paths ...string) Option

WithCRDs adds CRDs to the test environment using paths.

func WithScheme added in v0.16.0

func WithScheme(addToScheme ...AddToSchemeFunc) Option

WithScheme sets the scheme for the test environment.

func WithWebhookManifests added in v0.16.0

func WithWebhookManifests(paths ...string) Option

WithWebhookManifests adds CRDs to the test environment using paths.

type SetupFunc added in v0.16.0

type SetupFunc func(cfg *rest.Config, mgr ctrl.Manager) error

Jump to

Keyboard shortcuts

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