testtools

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package testtools provides comprehensive testing utilities for controller-runtime based controllers. Fixed version for Nephoran Intent Operator integration tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetScenarioConfigs

func GetScenarioConfigs() map[string]TestScenarioConfig

func GetUniqueName

func GetUniqueName(prefix string) string

func GetUniqueNamespace

func GetUniqueNamespace(prefix string) string

func IsRunningInCI

func IsRunningInCI() bool

Types

type BenchmarkConfig

type BenchmarkConfig struct {
	Enabled bool

	Duration time.Duration

	MemProfile bool

	CPUProfile bool

	OutputPath string
}

func GetBenchmarkConfig

func GetBenchmarkConfig() *BenchmarkConfig

type CleanupPolicy

type CleanupPolicy string

CleanupPolicy defines how resources should be cleaned up.

const (
	CleanupPolicyDelete CleanupPolicy = "delete"

	CleanupPolicyRetain CleanupPolicy = "retain"

	CleanupPolicyOrphan CleanupPolicy = "orphan"
)
const (
	CleanupPolicyDelete CleanupPolicy = "delete"
	CleanupPolicyRetain CleanupPolicy = "retain"
	CleanupPolicyOrphan CleanupPolicy = "orphan"
)

type CoverageConfig

type CoverageConfig struct {
	Enabled bool

	MinimumThreshold float64

	OutputFormat string

	OutputPath string

	IncludePatterns []string

	ExcludePatterns []string
}

func GetCoverageConfig

func GetCoverageConfig() *CoverageConfig

type E2NodeSetTestConfig

type E2NodeSetTestConfig struct {
	DefaultReplicas int32

	MaxReplicas int32

	DefaultRicEndpoint string

	ScaleUpTimeout time.Duration

	ScaleDownTimeout time.Duration

	HealthCheckInterval time.Duration
}

type EdgeControllerTestConfig

type EdgeControllerTestConfig struct {
	NodeDiscoveryInterval time.Duration

	HealthCheckInterval time.Duration

	DeploymentTimeout time.Duration

	MaxLatencyMs int

	ResourceThreshold float64
}

type EnvtestBinaryManager

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

func NewEnvtestBinaryManager

func NewEnvtestBinaryManager() *EnvtestBinaryManager

func (*EnvtestBinaryManager) EnsureBinariesInstalled

func (ebm *EnvtestBinaryManager) EnsureBinariesInstalled(ctx context.Context) error

func (*EnvtestBinaryManager) GetBinaryDirectory

func (ebm *EnvtestBinaryManager) GetBinaryDirectory() string

func (*EnvtestBinaryManager) GetBinaryPath

func (ebm *EnvtestBinaryManager) GetBinaryPath(binary string) string

func (*EnvtestBinaryManager) SetupEnvironment

func (ebm *EnvtestBinaryManager) SetupEnvironment()

func (*EnvtestBinaryManager) ValidateInstallation

func (ebm *EnvtestBinaryManager) ValidateInstallation(ctx context.Context) error

type NetworkIntentTestConfig

type NetworkIntentTestConfig struct {
	MaxRetries int

	RetryDelay time.Duration

	ProcessingTimeout time.Duration

	DeploymentTimeout time.Duration

	GitOperationTimeout time.Duration

	LLMTimeout time.Duration
}

type OranControllerTestConfig

type OranControllerTestConfig struct {
	DeploymentReadyTimeout time.Duration

	O1ConfigurationTimeout time.Duration

	A1PolicyTimeout time.Duration

	HealthCheckInterval time.Duration
}

type TestConfig

type TestConfig struct {
	DefaultTimeout time.Duration

	ReconcileTimeout time.Duration

	EventuallyTimeout time.Duration

	ConsistentlyDuration time.Duration

	DefaultInterval time.Duration

	ReconcileInterval time.Duration

	E2NodeSetConfig E2NodeSetTestConfig

	NetworkIntentConfig NetworkIntentTestConfig

	OranControllerConfig OranControllerTestConfig

	EdgeControllerConfig EdgeControllerTestConfig

	TrafficControllerConfig TrafficControllerTestConfig
}

func GetCITestConfig

func GetCITestConfig() *TestConfig

func GetDefaultTestConfig

func GetDefaultTestConfig() *TestConfig

func GetDevelopmentTestConfig

func GetDevelopmentTestConfig() *TestConfig

type TestEnvironment

type TestEnvironment struct {
	// Core Components
	Cfg          *rest.Config
	K8sClient    client.Client
	K8sClientSet *kubernetes.Clientset
	TestEnv      *envtest.Environment
	Scheme       *runtime.Scheme

	// Manager and Controllers
	Manager       ctrl.Manager
	ManagerCtx    context.Context
	ManagerCancel context.CancelFunc
	ManagerOnce   sync.Once
	// contains filtered or unexported fields
}

TestEnvironment provides a comprehensive test environment for controller testing.

func SetupTestEnvironment

func SetupTestEnvironment() (*TestEnvironment, error)

SetupTestEnvironment creates and starts a comprehensive test environment.

func SetupTestEnvironmentForCI

func SetupTestEnvironmentForCI() (*TestEnvironment, error)

func SetupTestEnvironmentForDevelopment

func SetupTestEnvironmentForDevelopment() (*TestEnvironment, error)

func SetupTestEnvironmentWithBinaryCheck

func SetupTestEnvironmentWithBinaryCheck(options TestEnvironmentOptions) (*TestEnvironment, error)

func SetupTestEnvironmentWithOptions

func SetupTestEnvironmentWithOptions(options TestEnvironmentOptions) (*TestEnvironment, error)

SetupTestEnvironmentWithOptions creates and starts a test environment with custom options.

func (*TestEnvironment) AddCleanupFunc

func (te *TestEnvironment) AddCleanupFunc(f func() error)

func (*TestEnvironment) CleanupNamespace

func (te *TestEnvironment) CleanupNamespace(namespace string) error

func (*TestEnvironment) CleanupNamespaceWithTimeout

func (te *TestEnvironment) CleanupNamespaceWithTimeout(namespace string, timeout time.Duration) error

func (*TestEnvironment) Consistently

func (te *TestEnvironment) Consistently(f func() bool, msgAndArgs ...interface{}) AsyncAssertion

func (*TestEnvironment) CreateManager

func (te *TestEnvironment) CreateManager() (ctrl.Manager, error)

func (*TestEnvironment) CreateManagerWithOptions

func (te *TestEnvironment) CreateManagerWithOptions(opts ctrl.Options) (ctrl.Manager, error)

func (*TestEnvironment) CreateNamespace

func (te *TestEnvironment) CreateNamespace(name string) error

CreateNamespace creates a namespace for testing.

func (*TestEnvironment) CreateNamespaceWithLabels

func (te *TestEnvironment) CreateNamespaceWithLabels(name string, labels map[string]string) error

func (*TestEnvironment) CreateTestE2NodeSet

func (te *TestEnvironment) CreateTestE2NodeSet(name, namespace string, replicas int32) (*nephoranv1.E2NodeSet, error)

func (*TestEnvironment) CreateTestManagedElement

func (te *TestEnvironment) CreateTestManagedElement(name, namespace string) (*nephoranv1.ManagedElement, error)

func (*TestEnvironment) CreateTestNetworkIntent

func (te *TestEnvironment) CreateTestNetworkIntent(name, namespace, intent string) (*nephoranv1.NetworkIntent, error)

func (*TestEnvironment) CreateTestObject

func (te *TestEnvironment) CreateTestObject(obj client.Object) error

func (*TestEnvironment) DeleteNamespace

func (te *TestEnvironment) DeleteNamespace(name string) error

func (*TestEnvironment) DeleteTestObject

func (te *TestEnvironment) DeleteTestObject(obj client.Object) error

func (*TestEnvironment) Eventually

func (te *TestEnvironment) Eventually(f func() bool, msgAndArgs ...interface{}) AsyncAssertion

func (*TestEnvironment) GetContext

func (te *TestEnvironment) GetContext() context.Context

func (*TestEnvironment) GetContextWithDeadline

func (te *TestEnvironment) GetContextWithDeadline(deadline time.Time) (context.Context, context.CancelFunc)

func (*TestEnvironment) GetContextWithTimeout

func (te *TestEnvironment) GetContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)

func (*TestEnvironment) GetDefaultInterval

func (te *TestEnvironment) GetDefaultInterval() time.Duration

func (*TestEnvironment) GetDefaultTimeout

func (te *TestEnvironment) GetDefaultTimeout() time.Duration

func (*TestEnvironment) GetDiscoveryClient

func (te *TestEnvironment) GetDiscoveryClient() discovery.DiscoveryInterface

func (*TestEnvironment) GetEventRecorder

func (te *TestEnvironment) GetEventRecorder() record.EventRecorder

func (*TestEnvironment) GetOptions

func (te *TestEnvironment) GetOptions() TestEnvironmentOptions

func (*TestEnvironment) GetScheme

func (te *TestEnvironment) GetScheme() *runtime.Scheme

GetScheme returns the runtime scheme.

func (*TestEnvironment) GetTestObject

func (te *TestEnvironment) GetTestObject(key types.NamespacedName, obj client.Object) error

func (*TestEnvironment) InstallCRDs

func (te *TestEnvironment) InstallCRDs(crdPaths ...string) error

func (*TestEnvironment) IsStarted

func (te *TestEnvironment) IsStarted() bool

func (*TestEnvironment) ListTestObjects

func (te *TestEnvironment) ListTestObjects(list client.ObjectList, opts ...client.ListOption) error

func (*TestEnvironment) NamespaceExists

func (te *TestEnvironment) NamespaceExists(name string) bool

func (*TestEnvironment) StartManager

func (te *TestEnvironment) StartManager() error

func (*TestEnvironment) StopManager

func (te *TestEnvironment) StopManager()

func (*TestEnvironment) TeardownTestEnvironment

func (te *TestEnvironment) TeardownTestEnvironment()

TeardownTestEnvironment stops and cleans up the test environment.

func (*TestEnvironment) UpdateTestObject

func (te *TestEnvironment) UpdateTestObject(obj client.Object) error

func (*TestEnvironment) VerifyCRDInstallation

func (te *TestEnvironment) VerifyCRDInstallation() error

VerifyCRDInstallation verifies that all expected CRDs are installed and ready.

func (*TestEnvironment) WaitForCacheSync

func (te *TestEnvironment) WaitForCacheSync(mgr ctrl.Manager) error

func (*TestEnvironment) WaitForCacheSyncWithTimeout

func (te *TestEnvironment) WaitForCacheSyncWithTimeout(mgr ctrl.Manager, timeout time.Duration) error

func (*TestEnvironment) WaitForE2NodeSetReady

func (te *TestEnvironment) WaitForE2NodeSetReady(namespacedName types.NamespacedName, expectedReplicas int32) error

func (*TestEnvironment) WaitForManagedElementReady

func (te *TestEnvironment) WaitForManagedElementReady(namespacedName types.NamespacedName) error

func (*TestEnvironment) WaitForManagerReady

func (te *TestEnvironment) WaitForManagerReady() error

func (*TestEnvironment) WaitForNetworkIntentReady

func (te *TestEnvironment) WaitForNetworkIntentReady(namespacedName types.NamespacedName) error

func (*TestEnvironment) WaitForResourceReady

func (te *TestEnvironment) WaitForResourceReady(obj client.Object, timeout time.Duration) error

WaitForResourceReady waits for a specific resource to be ready.

type TestEnvironmentOptions

type TestEnvironmentOptions struct {
	// CRD and Webhook Configuration
	CRDDirectoryPaths        []string
	WebhookInstallOptions    envtest.WebhookInstallOptions
	AttachControlPlaneOutput bool
	UseExistingCluster       *bool

	// Environment Variables
	EnvironmentVariables map[string]string

	// Binary Assets
	BinaryAssetsDirectory string

	// Timeouts and Intervals
	ControlPlaneStartTimeout time.Duration
	ControlPlaneStopTimeout  time.Duration
	APIServerReadyTimeout    time.Duration

	// Test Configuration
	EnableWebhooks       bool
	EnableMetrics        bool
	EnableHealthChecks   bool
	EnableLeaderElection bool
	EnableProfiling      bool

	// Namespace Configuration
	DefaultNamespace       string
	CreateDefaultNamespace bool
	NamespaceCleanupPolicy CleanupPolicy

	// Scheme Configuration
	SchemeBuilders []func(*runtime.Scheme) error

	// Resource Limits
	MemoryLimit string
	CPULimit    string

	// CI/Development Mode
	CIMode          bool
	DevelopmentMode bool
	VerboseLogging  bool
}

TestEnvironmentOptions configures the test environment setup.

func CITestEnvironmentOptions

func CITestEnvironmentOptions() TestEnvironmentOptions

func DefaultTestEnvironmentOptions

func DefaultTestEnvironmentOptions() TestEnvironmentOptions

DefaultTestEnvironmentOptions returns sensible defaults for test environment setup.

func DevelopmentTestEnvironmentOptions

func DevelopmentTestEnvironmentOptions() TestEnvironmentOptions

func DisasterRecoveryTestEnvironmentOptions

func DisasterRecoveryTestEnvironmentOptions() TestEnvironmentOptions

func EnhancedTestEnvironmentOptions

func EnhancedTestEnvironmentOptions() TestEnvironmentOptions

func GetRecommendedOptions

func GetRecommendedOptions() TestEnvironmentOptions

type TestScenarioConfig

type TestScenarioConfig struct {
	Name string

	Description string

	TimeoutOverride *time.Duration

	RetryCount *int

	Parallel bool

	Tags []string
}

type TrafficControllerTestConfig

type TrafficControllerTestConfig struct {
	HealthCheckInterval time.Duration

	RoutingDecisionInterval time.Duration

	MetricsCollectionInterval time.Duration

	FailoverThreshold float64

	RecoveryThreshold float64
}

Jump to

Keyboard shortcuts

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