testing

package
v0.0.0-...-94c4bcd Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNamespaceIfNotExists

func CreateNamespaceIfNotExists(ctx context.Context, c client.Client, name string)

CreateNamespaceIfNotExists creates a namespace if it doesn't exist

func GenerateUniqueTestName

func GenerateUniqueTestName(prefix string) string

GenerateUniqueTestName generates a unique namespace name with prefix

func ProjectRoot

func ProjectRoot() string

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

Types

type AddToSchemeFunc

type AddToSchemeFunc func(scheme *runtime.Scheme) error

type Cleaner

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

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

func (*Cleaner) DeleteAll

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

type Client

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

func (c *Client) UsingExistingCluster() bool

type Config

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

func Configure

func Configure(options ...Option) *Config

Configure creates a new configuration for the Kubernetes EnvTest.

func NewEnvTest

func NewEnvTest(options ...Option) *Config

NewEnvTest prepares k8s EnvTest with prereq

func (*Config) Start

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

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

WithControllers register controllers under tests required for the test suite.

func (*Config) WithWebhooks

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

WithWebhooks register webhooks under tests required for the test suite.

type Option

type Option func(target *envtest.Environment)

func WithCRDs

func WithCRDs(paths ...string) Option

WithCRDs adds CRDs to the test environment using paths.

func WithScheme

func WithScheme(addToScheme ...AddToSchemeFunc) Option

WithScheme sets the scheme for the test environment.

func WithWebhookManifests

func WithWebhookManifests(paths ...string) Option

WithWebhookManifests adds CRDs to the test environment using paths.

type SetupFunc

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

Jump to

Keyboard shortcuts

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