envtest

package
v3.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// PublishServiceName is the name of the publish service used in Gateway API tests.
	PublishServiceName = "publish-svc"
)

Variables

View Source
var DefaultEnvTestOpts = Options{
	InstallGatewayCRDs: true,
	InstallKongCRDs:    true,
}

Functions

func AdminAPIOptFns

func AdminAPIOptFns(fns ...mocks.AdminAPIHandlerOpt) []mocks.AdminAPIHandlerOpt

AdminAPIOptFns wraps a variadic list of mocks.AdminAPIHandlerOpt and returns a slice containing all of them. The purpose of this is func is to make the call sites a bit less verbose.

NOTE: Ideally we'd refactor the RunManager() so that it'd not need to accept an empty slice of mocks.AdminAPIHandlerOpt or a call to AdminAPIOptFns() with no arguments but we can't accept 2 variadic list parameters. A slight refactor might be beneficial here.

func ConfigForEnvConfig

func ConfigForEnvConfig(t *testing.T, envcfg *rest.Config, opts ...mocks.AdminAPIHandlerOpt) manager.Config

ConfigForEnvConfig prepares a manager.Config for use in tests It will start a mock Admin API server which will be set in KIC's config and which will be automatically stopped during test cleanup.

func CreateNamespace

func CreateNamespace(ctx context.Context, t *testing.T, client ctrlclient.Client) corev1.Namespace

CreateNamespace creates namespace using the provided client and returns it.

func CreatePod

func CreatePod(ctx context.Context, t *testing.T, client ctrlclient.Client, ns string) corev1.Pod

CreatePod creates pod using the provided client and returns it.

func NewControllerClient

func NewControllerClient(t *testing.T, scheme *runtime.Scheme, cfg *rest.Config) ctrlclient.Client

NewControllerClient returns a new controller-runtime Client for provided runtime.Scheme and rest.Config.

func RunManager

func RunManager(
	ctx context.Context,
	t *testing.T,
	envcfg *rest.Config,
	adminAPIOpts []mocks.AdminAPIHandlerOpt,
	modifyCfgFns ...func(cfg *manager.Config),
) (cfg manager.Config, loggerHook *observer.ObservedLogs)

RunManager runs the manager in a goroutine. It's possible to modify the manager's configuration by passing in modifyCfgFns. The manager is stopped when the context is canceled.

func Scheme

func Scheme(t *testing.T, opts ...SchemeOption) *k8sruntime.Scheme

Scheme returns a new scheme with the default Kubernetes types registered. It accepts optional SchemeOptions to register additional types.

func Setup

func Setup(t *testing.T, scheme *k8sruntime.Scheme, optModifiers ...OptionModifier) *rest.Config

Setup sets up the envtest environment which will be stopped on test cleanup using t.Cleanup().

Note: If you want apiserver output on stdout set KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT to true when running tests.

func StartAdminAPIServerMock

func StartAdminAPIServerMock(t *testing.T, opts ...mocks.AdminAPIHandlerOpt) *httptest.Server

StartAdminAPIServerMock starts a mock Kong Admin API server. It accepts a variadic list of options which can configure the test server.

Server's .Close() method will be called during test's cleanup.

func StartReconcilers

func StartReconcilers(ctx context.Context, t *testing.T, scheme *runtime.Scheme, cfg *rest.Config, reconcilers ...controllers.Reconciler)

StartReconcilers creates a controller manager and starts the provided reconciler as its runnable. It also adds a t.Cleanup which waits for the manager to exit so that the test can be self contained and logs from different tests' managers don't mix up.

func WithDiagnosticsServer

func WithDiagnosticsServer(port int) func(cfg *manager.Config)

func WithGatewayAPI

func WithGatewayAPI(t *testing.T, s *k8sruntime.Scheme)

WithGatewayAPI registers the Gateway API types with the scheme.

func WithGatewayAPIControllers

func WithGatewayAPIControllers() func(cfg *manager.Config)

func WithGatewayFeatureEnabled

func WithGatewayFeatureEnabled(cfg *manager.Config)

func WithHealthProbePort

func WithHealthProbePort(port int) func(cfg *manager.Config)

func WithIngressClass

func WithIngressClass(name string) func(cfg *manager.Config)

func WithKong

func WithKong(t *testing.T, s *k8sruntime.Scheme)

WithKong registers the Kong types with the scheme.

func WithProfiling

func WithProfiling() func(cfg *manager.Config)

func WithProxySyncSeconds

func WithProxySyncSeconds(period float32) func(cfg *manager.Config)

func WithPublishService

func WithPublishService(namespace string) func(cfg *manager.Config)

func WithPublishStatusAddress

func WithPublishStatusAddress(address string) func(cfg *manager.Config)

func WithUpdateStatus

func WithUpdateStatus() func(cfg *manager.Config)

Types

type ModifyManagerConfigFn

type ModifyManagerConfigFn func(cfg *manager.Config)

type OptionModifier

type OptionModifier func(Options) Options

func WithInstallGatewayCRDs

func WithInstallGatewayCRDs(install bool) OptionModifier

func WithInstallKongCRDs

func WithInstallKongCRDs(install bool) OptionModifier

type Options

type Options struct {
	InstallGatewayCRDs bool
	InstallKongCRDs    bool
}

type SchemeOption

type SchemeOption func(t *testing.T, s *k8sruntime.Scheme)

Jump to

Keyboard shortcuts

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