Documentation
¶
Overview ¶
Package testing provides unified test helper utilities for opencenter-cli.
This package consolidates common test setup patterns into reusable functions, eliminating duplication across test files and providing consistent test infrastructure. All helpers use t.Helper() for proper test failure reporting and t.TempDir() for automatic cleanup.
Key Features ¶
- Temporary file and directory creation with automatic cleanup
- Assertion helpers for common test conditions
- Consistent error handling in tests
- Proper test failure line reporting
Usage Examples ¶
Creating temporary configuration files:
func TestConfigLoader(t *testing.T) {
configContent := `
cluster:
name: test-cluster
provider: openstack
`
configPath := testing.CreateTempConfig(t, configContent)
// configPath points to a temporary config.yaml file
// The file and directory are automatically cleaned up after the test
config, err := LoadConfig(configPath)
testing.AssertNoError(t, err, "failed to load config")
testing.AssertEqual(t, config.Cluster.Name, "test-cluster", "cluster name")
}
Creating temporary directory structures:
func TestGitOpsGeneration(t *testing.T) {
files := map[string]string{
"infrastructure/main.tf": "# Terraform config",
"applications/kustomization.yaml": "apiVersion: kustomize.config.k8s.io/v1beta1",
"secrets/age-key.txt": "AGE-SECRET-KEY-...",
}
tmpDir := testing.CreateTempDir(t, files)
// tmpDir contains the specified directory structure
// All files and directories are automatically cleaned up after the test
err := GenerateGitOps(tmpDir)
testing.AssertNoError(t, err, "failed to generate GitOps")
testing.AssertFileExists(t, filepath.Join(tmpDir, "infrastructure/main.tf"))
}
Using assertion helpers:
func TestValidation(t *testing.T) {
config := &Config{Name: "test"}
// Assert no error
err := ValidateConfig(config)
testing.AssertNoError(t, err, "config validation failed")
// Assert error is returned
invalidConfig := &Config{}
err = ValidateConfig(invalidConfig)
testing.AssertError(t, err, "expected validation error for empty config")
// Assert equality
testing.AssertEqual(t, config.Name, "test", "config name")
// Assert file existence
testing.AssertFileExists(t, "/path/to/file")
testing.AssertFileNotExists(t, "/path/to/deleted/file")
}
Common Test Setup Patterns ¶
Pattern 1: Testing configuration loading
func TestConfigLoad(t *testing.T) {
configPath := testing.CreateTempConfig(t, validConfigYAML)
config, err := LoadConfig(configPath)
testing.AssertNoError(t, err, "failed to load config")
// Test config properties...
}
Pattern 2: Testing file generation
func TestFileGeneration(t *testing.T) {
tmpDir := testing.CreateTempDir(t, map[string]string{
"input.yaml": inputContent,
})
err := GenerateFiles(tmpDir)
testing.AssertNoError(t, err, "generation failed")
testing.AssertFileExists(t, filepath.Join(tmpDir, "output.yaml"))
}
Pattern 3: Testing validation errors
func TestValidationErrors(t *testing.T) {
invalidConfig := &Config{Name: ""}
err := ValidateConfig(invalidConfig)
testing.AssertError(t, err, "expected validation error")
// Optionally check error message
if !strings.Contains(err.Error(), "name is required") {
t.Errorf("unexpected error message: %v", err)
}
}
Pattern 4: Testing with multiple files
func TestMultiFileProcessing(t *testing.T) {
files := map[string]string{
"config/cluster.yaml": clusterConfig,
"config/services.yaml": servicesConfig,
"secrets/credentials.yaml": credentials,
}
tmpDir := testing.CreateTempDir(t, files)
result, err := ProcessConfigs(tmpDir)
testing.AssertNoError(t, err, "processing failed")
testing.AssertEqual(t, result.ClusterCount, 1, "cluster count")
}
Automatic Cleanup ¶
All test helpers use t.TempDir() which provides automatic cleanup:
- Temporary directories are created in the system temp directory
- Cleanup happens automatically when the test completes
- Cleanup occurs even if the test fails or panics
- No manual cleanup code is required
Proper Error Reporting ¶
All helpers use t.Helper() to ensure test failures report the correct line:
// Without t.Helper(), failures would report the line inside the helper // With t.Helper(), failures report the line in your test that called the helper testing.AssertNoError(t, err, "operation failed") // Failure reports THIS line
Migration from Duplicate Helpers ¶
If you have existing test code with duplicate helper implementations:
- Replace local CreateTempConfig with testing.CreateTempConfig
- Replace local CreateTempDir with testing.CreateTempDir
- Replace custom assertions with testing.Assert* functions
- Remove duplicate helper implementations
Before:
func createTestConfig(t *testing.T, content string) string {
tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "config.yaml")
os.WriteFile(path, []byte(content), 0644)
return path
}
After:
configPath := testing.CreateTempConfig(t, content)
Best Practices ¶
- Use CreateTempConfig for single configuration files
- Use CreateTempDir for complex directory structures
- Use Assert* helpers for common test conditions
- Always provide descriptive messages to assertion helpers
- Let t.TempDir() handle cleanup automatically
- Use t.Helper() in your own test helpers
Performance ¶
Test helpers are optimized for test execution speed:
- CreateTempConfig: ~1ms per call
- CreateTempDir: ~2-5ms depending on file count
- Assertion helpers: <0.1ms per call
The overhead is negligible compared to typical test execution time.
Index ¶
- func AssertEqual(t *testing.T, got, want interface{}, message string)
- func AssertError(t *testing.T, err error, message string)
- func AssertFileExists(t *testing.T, path string)
- func AssertFileNotExists(t *testing.T, path string)
- func AssertNoError(t *testing.T, err error, message string)
- func CreateTempConfig(t *testing.T, content string) string
- func CreateTempDir(t *testing.T, files map[string]string) string
- func LoadConfig(t *testing.T, name string) v2.Config
- func SaveConfig(t *testing.T, cfg v2.Config)
- func SaveConfigWithPathResolver(t *testing.T, cfg v2.Config, pathResolver *paths.PathResolver)
- func SaveConfigWithValidation(t *testing.T, cfg v2.Config) error
- func ValidateConfig(t *testing.T, cfg v2.Config) error
- type AddWithContextCall
- type BenchmarkFramework
- func (fw *BenchmarkFramework) BenchmarkConcurrentOperations(b *testing.B, operation func() error, concurrency int)
- func (fw *BenchmarkFramework) BenchmarkConfigBuilding(b *testing.B, buildFunc func() (v2.Config, error))
- func (fw *BenchmarkFramework) BenchmarkConfigValidation(b *testing.B, cfg v2.Config, validateFunc func(v2.Config) error)
- func (fw *BenchmarkFramework) BenchmarkMemoryUsage(b *testing.B, operation func() error)
- func (fw *BenchmarkFramework) BenchmarkTemplateRendering(b *testing.B, engine template.TemplateEngine, templatePath string, ...)
- func (fw *BenchmarkFramework) CompareOperations(b *testing.B, name1 string, op1 func() error, name2 string, op2 func() error)
- func (fw *BenchmarkFramework) CompareToBaseline(b *testing.B, name string, nsPerOp int64) bool
- func (fw *BenchmarkFramework) CreateBenchmarkConfig(provider string) v2.Config
- func (fw *BenchmarkFramework) CreateBenchmarkTemplate(b *testing.B, name string, size int) string
- func (fw *BenchmarkFramework) CreateBenchmarkTemplateData() map[string]interface{}
- func (fw *BenchmarkFramework) CreateLargeBenchmarkConfig(provider string) v2.Config
- func (fw *BenchmarkFramework) CreateLargeBenchmarkTemplateData() map[string]interface{}
- func (fw *BenchmarkFramework) LoadBenchmarkResults(b *testing.B, filename string) error
- func (fw *BenchmarkFramework) MeasureOperation(b *testing.B, name string, operation func() error) time.Duration
- func (fw *BenchmarkFramework) RecordBaseline(name string, result BenchmarkResult)
- func (fw *BenchmarkFramework) RunBenchmarkSuite(b *testing.B, suite map[string]func(*testing.B))
- func (fw *BenchmarkFramework) SaveBenchmarkResults(b *testing.B, filename string) error
- type BenchmarkResult
- type ConfigGenerator
- type GitOpsDataGenerator
- type InfrastructureDataGenerator
- type MigrateConfigCall
- type MigrationPathCall
- type MockAuthProvider
- func (m *MockAuthProvider) AuthenticateSession(ctx context.Context, credentials map[string]string) (interface{}, error)
- func (m *MockAuthProvider) RefreshSession(ctx context.Context, session interface{}) error
- func (m *MockAuthProvider) ValidatePermission(session interface{}, permission interface{}) error
- type MockConfigBuilder
- func (m *MockConfigBuilder) Build() (v2.Config, error)
- func (m *MockConfigBuilder) Validate() []error
- func (m *MockConfigBuilder) WithClusterName(name string) *MockConfigBuilder
- func (m *MockConfigBuilder) WithKubernetesVersion(version string) *MockConfigBuilder
- func (m *MockConfigBuilder) WithNetworking(cfg interface{}) *MockConfigBuilder
- func (m *MockConfigBuilder) WithNodeCounts(masters, workers int) *MockConfigBuilder
- func (m *MockConfigBuilder) WithOrganization(org string) *MockConfigBuilder
- func (m *MockConfigBuilder) WithOverride(path string, value interface{}) *MockConfigBuilder
- func (m *MockConfigBuilder) WithProvider(provider string) *MockConfigBuilder
- func (m *MockConfigBuilder) WithServices(services ...string) *MockConfigBuilder
- type MockConfigValidator
- type MockErrorAggregator
- type MockGenerationStage
- func (m *MockGenerationStage) Execute(ctx context.Context, workspace interface{}) error
- func (m *MockGenerationStage) Name() string
- func (m *MockGenerationStage) Rollback(ctx context.Context, workspace interface{}) error
- func (m *MockGenerationStage) Validate(ctx context.Context, workspace interface{}) error
- type MockGitOpsGenerator
- type MockMCPServer
- func (m *MockMCPServer) RegisterPrompts(prompts []interface{}) error
- func (m *MockMCPServer) RegisterResources(resources []interface{}) error
- func (m *MockMCPServer) RegisterTools(tools []interface{}) error
- func (m *MockMCPServer) SetAuthProvider(provider interface{}) error
- func (m *MockMCPServer) Start(ctx context.Context) error
- func (m *MockMCPServer) Stop(ctx context.Context) error
- type MockMCPSession
- type MockMigrationManager
- func (m *MockMigrationManager) GetCurrentVersion() string
- func (m *MockMigrationManager) GetSupportedVersions() []string
- func (m *MockMigrationManager) MigrateConfig(cfg v2.Config, targetVersion string) (v2.Config, error)
- func (m *MockMigrationManager) ValidateMigrationPath(fromVersion, toVersion string) error
- type MockServicePlugin
- func (m *MockServicePlugin) Name() string
- func (m *MockServicePlugin) Render(ctx context.Context, cfg v2.Config, workspace interface{}) error
- func (m *MockServicePlugin) Status(cfg v2.Config) interface{}
- func (m *MockServicePlugin) Type() string
- func (m *MockServicePlugin) Validate(cfg v2.Config) error
- type MockServiceRegistry
- func (m *MockServiceRegistry) GetEnabledServices(cfg v2.Config) []interface{}
- func (m *MockServiceRegistry) GetService(name string) (interface{}, error)
- func (m *MockServiceRegistry) RegisterService(service interface{}) error
- func (m *MockServiceRegistry) ResolveDependencies(services []string) ([]interface{}, error)
- func (m *MockServiceRegistry) ValidateDependencies(services []string) error
- type MockTemplateEngine
- func (m *MockTemplateEngine) ClearCache()
- func (m *MockTemplateEngine) RegisterFunction(name string, fn interface{})
- func (m *MockTemplateEngine) Render(ctx context.Context, templatePath string, data interface{}) ([]byte, error)
- func (m *MockTemplateEngine) SetCacheEnabled(enabled bool)
- func (m *MockTemplateEngine) ValidateTemplate(templatePath string) error
- type MockTemplateRegistry
- func (m *MockTemplateRegistry) GetTemplate(name string) (interface{}, error)
- func (m *MockTemplateRegistry) GetTemplatesForEnabledServices(enabledServices []string) []interface{}
- func (m *MockTemplateRegistry) GetTemplatesForProvider(provider string) []interface{}
- func (m *MockTemplateRegistry) GetTemplatesForService(service string) []interface{}
- func (m *MockTemplateRegistry) GetTemplatesForType(templateType interface{}) []interface{}
- func (m *MockTemplateRegistry) ListTemplates() []interface{}
- func (m *MockTemplateRegistry) RegisterTemplate(template interface{}) error
- func (m *MockTemplateRegistry) ResolveTemplateDependencies(templates []string) ([]interface{}, error)
- func (m *MockTemplateRegistry) UnregisterTemplate(name string) error
- type NetworkingDataGenerator
- type RenderCall
- type RenderPluginCall
- type ScenarioGenerator
- func (g *ScenarioGenerator) GenerateComplianceScenario(provider string, framework string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateDevelopmentScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateDisasterRecoveryScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateEdgeCaseScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateIntegrationTestScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateMigrationScenario(fromProvider, toProvider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateMultiRegionScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GeneratePerformanceTestScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateProductionScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateSecurityAuditScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateStagingScenario(provider string) map[string]interface{}
- func (g *ScenarioGenerator) GenerateUpgradeScenario(provider string) map[string]interface{}
- type SecurityDataGenerator
- type ServiceDataGenerator
- type TemplateDataGenerator
- type TestFramework
- func (fw *TestFramework) AssertDirExists(t *testing.T, path string)
- func (fw *TestFramework) AssertDirNotExists(t *testing.T, path string)
- func (fw *TestFramework) AssertFileExists(t *testing.T, path string)
- func (fw *TestFramework) AssertFileNotExists(t *testing.T, path string)
- func (fw *TestFramework) Cleanup()
- func (fw *TestFramework) CreateTestConfig(provider string) v2.Config
- func (fw *TestFramework) CreateTestGitOpsConfig() map[string]interface{}
- func (fw *TestFramework) CreateTestServiceDefinition() map[string]interface{}
- func (fw *TestFramework) CreateTestTemplateData() map[string]interface{}
- func (fw *TestFramework) WriteFile(t *testing.T, filename string, content []byte) string
- func (fw *TestFramework) WriteTemplate(t *testing.T, filename string, content string) string
- type ValidatePermissionCall
- type WorkloadDataGenerator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqual ¶
AssertEqual fails the test if got != want.
func AssertError ¶
AssertError fails the test if err is nil.
func AssertFileExists ¶
AssertFileExists fails the test if file doesn't exist.
func AssertFileNotExists ¶
AssertFileNotExists fails the test if file exists.
func AssertNoError ¶
AssertNoError fails the test if err is not nil.
func CreateTempConfig ¶
CreateTempConfig creates a temporary config file for testing. It creates a temporary directory, writes the config content to a file, and returns the path to the config file. The directory is automatically cleaned up when the test completes.
func CreateTempDir ¶
CreateTempDir creates a temporary directory with specified files. The files parameter is a map where keys are file paths (relative to the temp dir) and values are the file contents. Parent directories are created automatically. The directory is automatically cleaned up when the test completes.
func LoadConfig ¶
LoadConfig is a test helper that loads a configuration using ConfigurationManager. It handles manager initialization and provides a clean API for tests.
func SaveConfig ¶
SaveConfig is a test helper that saves a configuration using ConfigurationManager. It handles manager initialization and provides a clean API for tests. Note: This skips validation to allow tests to save incomplete configs.
The function uses the organization from the config to determine the base directory. If the organization is empty, it defaults to "opencenter".
func SaveConfigWithPathResolver ¶
SaveConfigWithPathResolver is a test helper that saves a configuration using a custom PathResolver. This is useful for tests that use temporary directories. Note: This skips validation to allow tests to save incomplete configs.
func SaveConfigWithValidation ¶
SaveConfigWithValidation is a test helper that saves and validates a configuration. Use this when you want to test validation behavior.
Types ¶
type AddWithContextCall ¶
type AddWithContextCall struct {
Error error
Context interface{}
}
AddWithContextCall tracks a call to AddWithContext
type BenchmarkFramework ¶
type BenchmarkFramework struct {
// BaselineResults stores baseline performance metrics for comparison
BaselineResults map[string]BenchmarkResult
// ThresholdMultiplier is the acceptable performance degradation multiplier
// For example, 1.5 means 50% slower is acceptable
ThresholdMultiplier float64
// TempDir is the temporary directory for benchmark artifacts
TempDir string
// ConfigGenerator generates test configurations for benchmarks
ConfigGenerator *ConfigGenerator
// TemplateDataGenerator generates template data for benchmarks
TemplateDataGenerator *TemplateDataGenerator
}
BenchmarkFramework provides utilities for performance testing and regression detection. It helps measure and compare performance across different implementations and versions.
func NewBenchmarkFramework ¶
func NewBenchmarkFramework(b *testing.B) *BenchmarkFramework
NewBenchmarkFramework creates a new benchmark framework with default settings.
func NewBenchmarkFrameworkWithThreshold ¶
func NewBenchmarkFrameworkWithThreshold(b *testing.B, threshold float64) *BenchmarkFramework
NewBenchmarkFrameworkWithThreshold creates a benchmark framework with a custom threshold.
func (*BenchmarkFramework) BenchmarkConcurrentOperations ¶
func (fw *BenchmarkFramework) BenchmarkConcurrentOperations(b *testing.B, operation func() error, concurrency int)
BenchmarkConcurrentOperations benchmarks concurrent operations performance.
func (*BenchmarkFramework) BenchmarkConfigBuilding ¶
func (fw *BenchmarkFramework) BenchmarkConfigBuilding(b *testing.B, buildFunc func() (v2.Config, error))
BenchmarkConfigBuilding benchmarks configuration building performance.
func (*BenchmarkFramework) BenchmarkConfigValidation ¶
func (fw *BenchmarkFramework) BenchmarkConfigValidation(b *testing.B, cfg v2.Config, validateFunc func(v2.Config) error)
BenchmarkConfigValidation benchmarks configuration validation performance.
func (*BenchmarkFramework) BenchmarkMemoryUsage ¶
func (fw *BenchmarkFramework) BenchmarkMemoryUsage(b *testing.B, operation func() error)
BenchmarkMemoryUsage benchmarks memory usage for an operation.
func (*BenchmarkFramework) BenchmarkTemplateRendering ¶
func (fw *BenchmarkFramework) BenchmarkTemplateRendering(b *testing.B, engine template.TemplateEngine, templatePath string, data interface{})
BenchmarkTemplateRendering benchmarks template rendering performance.
func (*BenchmarkFramework) CompareOperations ¶
func (fw *BenchmarkFramework) CompareOperations(b *testing.B, name1 string, op1 func() error, name2 string, op2 func() error)
CompareOperations compares the performance of two operations.
func (*BenchmarkFramework) CompareToBaseline ¶
CompareToBaseline compares a benchmark result to the recorded baseline. Returns true if the performance is within acceptable threshold, false otherwise.
func (*BenchmarkFramework) CreateBenchmarkConfig ¶
func (fw *BenchmarkFramework) CreateBenchmarkConfig(provider string) v2.Config
CreateBenchmarkConfig creates a configuration for benchmarking.
func (*BenchmarkFramework) CreateBenchmarkTemplate ¶
CreateBenchmarkTemplate creates a template file for benchmarking.
func (*BenchmarkFramework) CreateBenchmarkTemplateData ¶
func (fw *BenchmarkFramework) CreateBenchmarkTemplateData() map[string]interface{}
CreateBenchmarkTemplateData creates template data for benchmarking.
func (*BenchmarkFramework) CreateLargeBenchmarkConfig ¶
func (fw *BenchmarkFramework) CreateLargeBenchmarkConfig(provider string) v2.Config
CreateLargeBenchmarkConfig creates a large configuration for stress testing.
func (*BenchmarkFramework) CreateLargeBenchmarkTemplateData ¶
func (fw *BenchmarkFramework) CreateLargeBenchmarkTemplateData() map[string]interface{}
CreateLargeBenchmarkTemplateData creates large template data for stress testing.
func (*BenchmarkFramework) LoadBenchmarkResults ¶
func (fw *BenchmarkFramework) LoadBenchmarkResults(b *testing.B, filename string) error
LoadBenchmarkResults loads benchmark results from a file for comparison.
func (*BenchmarkFramework) MeasureOperation ¶
func (fw *BenchmarkFramework) MeasureOperation(b *testing.B, name string, operation func() error) time.Duration
MeasureOperation measures the time taken by an operation.
func (*BenchmarkFramework) RecordBaseline ¶
func (fw *BenchmarkFramework) RecordBaseline(name string, result BenchmarkResult)
RecordBaseline records a baseline benchmark result for future comparison.
func (*BenchmarkFramework) RunBenchmarkSuite ¶
RunBenchmarkSuite runs a suite of related benchmarks.
func (*BenchmarkFramework) SaveBenchmarkResults ¶
func (fw *BenchmarkFramework) SaveBenchmarkResults(b *testing.B, filename string) error
SaveBenchmarkResults saves benchmark results to a file for historical comparison.
type BenchmarkResult ¶
type BenchmarkResult struct {
Name string
NsPerOp int64
AllocsPerOp int64
BytesPerOp int64
MemAllocsPerOp int64
MemBytesPerOp int64
Timestamp time.Time
Version string
Description string
}
BenchmarkResult captures the results of a benchmark run.
type ConfigGenerator ¶
type ConfigGenerator struct {
// contains filtered or unexported fields
}
ConfigGenerator provides methods for generating realistic test configurations
func NewConfigGenerator ¶
func NewConfigGenerator(seed int64) *ConfigGenerator
NewConfigGenerator creates a new configuration generator with a seeded random source
func (*ConfigGenerator) GenerateComplexConfig ¶
func (g *ConfigGenerator) GenerateComplexConfig(provider string) v2.Config
GenerateComplexConfig creates a complex configuration with many services enabled
func (*ConfigGenerator) GenerateConfig ¶
func (g *ConfigGenerator) GenerateConfig(provider string) v2.Config
GenerateConfig creates a realistic cluster configuration with random but valid values
func (*ConfigGenerator) GenerateMinimalConfig ¶
func (g *ConfigGenerator) GenerateMinimalConfig(provider string) v2.Config
GenerateMinimalConfig creates a minimal but valid configuration
type GitOpsDataGenerator ¶
type GitOpsDataGenerator struct {
// contains filtered or unexported fields
}
GitOpsDataGenerator provides methods for generating realistic GitOps test data
func NewGitOpsDataGenerator ¶
func NewGitOpsDataGenerator(seed int64) *GitOpsDataGenerator
NewGitOpsDataGenerator creates a new GitOps data generator
func (*GitOpsDataGenerator) GenerateGitOpsConfig ¶
func (g *GitOpsDataGenerator) GenerateGitOpsConfig() map[string]interface{}
GenerateGitOpsConfig creates a realistic GitOps configuration for testing
type InfrastructureDataGenerator ¶
type InfrastructureDataGenerator struct {
// contains filtered or unexported fields
}
InfrastructureDataGenerator provides methods for generating realistic infrastructure test data
func NewInfrastructureDataGenerator ¶
func NewInfrastructureDataGenerator(seed int64) *InfrastructureDataGenerator
NewInfrastructureDataGenerator creates a new infrastructure data generator
func (*InfrastructureDataGenerator) GenerateNodePool ¶
func (g *InfrastructureDataGenerator) GenerateNodePool() map[string]interface{}
GenerateNodePool creates a realistic node pool configuration for testing
type MigrateConfigCall ¶
MigrateConfigCall tracks a call to MigrateConfig
type MigrationPathCall ¶
MigrationPathCall tracks a call to ValidateMigrationPath
type MockAuthProvider ¶
type MockAuthProvider struct {
// Function customization
AuthenticateSessionFunc func(ctx context.Context, credentials map[string]string) (interface{}, error)
ValidatePermissionFunc func(session interface{}, permission interface{}) error
RefreshSessionFunc func(ctx context.Context, session interface{}) error
// Tracking fields
AuthenticateSessionCalls []map[string]string
ValidatePermissionCalls []ValidatePermissionCall
RefreshSessionCalls []interface{}
// contains filtered or unexported fields
}
MockAuthProvider provides a mock implementation of auth provider for testing.
func NewMockAuthProvider ¶
func NewMockAuthProvider() *MockAuthProvider
NewMockAuthProvider creates a new mock auth provider.
func (*MockAuthProvider) AuthenticateSession ¶
func (m *MockAuthProvider) AuthenticateSession(ctx context.Context, credentials map[string]string) (interface{}, error)
AuthenticateSession implements AuthProvider.AuthenticateSession
func (*MockAuthProvider) RefreshSession ¶
func (m *MockAuthProvider) RefreshSession(ctx context.Context, session interface{}) error
RefreshSession implements AuthProvider.RefreshSession
func (*MockAuthProvider) ValidatePermission ¶
func (m *MockAuthProvider) ValidatePermission(session interface{}, permission interface{}) error
ValidatePermission implements AuthProvider.ValidatePermission
type MockConfigBuilder ¶
type MockConfigBuilder struct {
// BuildFunc allows customizing the Build behavior
BuildFunc func() (v2.Config, error)
// ValidateFunc allows customizing the Validate behavior
ValidateFunc func() []error
// Tracking fields
BuildCalls int
ValidateCalls int
// contains filtered or unexported fields
}
MockConfigBuilder provides a mock implementation of config.ConfigBuilder for testing.
func NewMockConfigBuilder ¶
func NewMockConfigBuilder() *MockConfigBuilder
NewMockConfigBuilder creates a new mock config builder.
func (*MockConfigBuilder) Build ¶
func (m *MockConfigBuilder) Build() (v2.Config, error)
Build implements config.ConfigBuilder.Build
func (*MockConfigBuilder) Validate ¶
func (m *MockConfigBuilder) Validate() []error
Validate implements config.ConfigBuilder.Validate
func (*MockConfigBuilder) WithClusterName ¶
func (m *MockConfigBuilder) WithClusterName(name string) *MockConfigBuilder
WithClusterName implements config.ConfigBuilder.WithClusterName
func (*MockConfigBuilder) WithKubernetesVersion ¶
func (m *MockConfigBuilder) WithKubernetesVersion(version string) *MockConfigBuilder
WithKubernetesVersion implements config.ConfigBuilder.WithKubernetesVersion
func (*MockConfigBuilder) WithNetworking ¶
func (m *MockConfigBuilder) WithNetworking(cfg interface{}) *MockConfigBuilder
WithNetworking implements config.ConfigBuilder.WithNetworking
func (*MockConfigBuilder) WithNodeCounts ¶
func (m *MockConfigBuilder) WithNodeCounts(masters, workers int) *MockConfigBuilder
WithNodeCounts implements config.ConfigBuilder.WithNodeCounts
func (*MockConfigBuilder) WithOrganization ¶
func (m *MockConfigBuilder) WithOrganization(org string) *MockConfigBuilder
WithOrganization implements config.ConfigBuilder.WithOrganization
func (*MockConfigBuilder) WithOverride ¶
func (m *MockConfigBuilder) WithOverride(path string, value interface{}) *MockConfigBuilder
WithOverride implements config.ConfigBuilder.WithOverride
func (*MockConfigBuilder) WithProvider ¶
func (m *MockConfigBuilder) WithProvider(provider string) *MockConfigBuilder
WithProvider implements config.ConfigBuilder.WithProvider
func (*MockConfigBuilder) WithServices ¶
func (m *MockConfigBuilder) WithServices(services ...string) *MockConfigBuilder
WithServices implements config.ConfigBuilder.WithServices
type MockConfigValidator ¶
type MockConfigValidator struct {
// ValidateFunc allows customizing the Validate behavior
ValidateFunc func(cfg v2.Config) []error
// Tracking fields
ValidateCalls []v2.Config
// contains filtered or unexported fields
}
MockConfigValidator provides a mock implementation of config.ConfigValidator for testing.
func NewMockConfigValidator ¶
func NewMockConfigValidator() *MockConfigValidator
NewMockConfigValidator creates a new mock config validator.
type MockErrorAggregator ¶
type MockErrorAggregator struct {
// Function customization
AddFunc func(err error)
AddWithContextFunc func(err error, context interface{})
HasErrorsFunc func() bool
ErrorsFunc func() []error
ReportFunc func() error
// Tracking fields
AddCalls []error
AddWithContextCalls []AddWithContextCall
HasErrorsCalls int
ErrorsCalls int
ReportCalls int
// contains filtered or unexported fields
}
MockErrorAggregator provides a mock implementation of error aggregator for testing.
func NewMockErrorAggregator ¶
func NewMockErrorAggregator() *MockErrorAggregator
NewMockErrorAggregator creates a new mock error aggregator.
func (*MockErrorAggregator) Add ¶
func (m *MockErrorAggregator) Add(err error)
Add implements ErrorAggregator.Add
func (*MockErrorAggregator) AddWithContext ¶
func (m *MockErrorAggregator) AddWithContext(err error, context interface{})
AddWithContext implements ErrorAggregator.AddWithContext
func (*MockErrorAggregator) Errors ¶
func (m *MockErrorAggregator) Errors() []error
Errors implements ErrorAggregator.Errors
func (*MockErrorAggregator) HasErrors ¶
func (m *MockErrorAggregator) HasErrors() bool
HasErrors implements ErrorAggregator.HasErrors
func (*MockErrorAggregator) Report ¶
func (m *MockErrorAggregator) Report() error
Report implements ErrorAggregator.Report
type MockGenerationStage ¶
type MockGenerationStage struct {
// Function customization
NameFunc func() string
ExecuteFunc func(ctx context.Context, workspace interface{}) error
RollbackFunc func(ctx context.Context, workspace interface{}) error
ValidateFunc func(ctx context.Context, workspace interface{}) error
// Tracking fields
ExecuteCalls []interface{}
RollbackCalls []interface{}
ValidateCalls []interface{}
// contains filtered or unexported fields
}
MockGenerationStage provides a mock implementation of generation stage for testing.
func NewMockGenerationStage ¶
func NewMockGenerationStage(name string) *MockGenerationStage
NewMockGenerationStage creates a new mock generation stage.
func (*MockGenerationStage) Execute ¶
func (m *MockGenerationStage) Execute(ctx context.Context, workspace interface{}) error
Execute implements GenerationStage.Execute
func (*MockGenerationStage) Name ¶
func (m *MockGenerationStage) Name() string
Name implements GenerationStage.Name
type MockGitOpsGenerator ¶
type MockGitOpsGenerator struct {
// Function customization
GenerateFunc func(ctx context.Context, cfg v2.Config) error
GenerateDryRunFunc func(ctx context.Context, cfg v2.Config) (interface{}, error)
RollbackFunc func(ctx context.Context, checkpointID string) error
// Tracking fields
GenerateCalls []v2.Config
GenerateDryRunCalls []v2.Config
RollbackCalls []string
// contains filtered or unexported fields
}
MockGitOpsGenerator provides a mock implementation of GitOps generator for testing.
func NewMockGitOpsGenerator ¶
func NewMockGitOpsGenerator() *MockGitOpsGenerator
NewMockGitOpsGenerator creates a new mock GitOps generator.
func (*MockGitOpsGenerator) GenerateDryRun ¶
func (m *MockGitOpsGenerator) GenerateDryRun(ctx context.Context, cfg v2.Config) (interface{}, error)
GenerateDryRun implements GitOpsGenerator.GenerateDryRun
type MockMCPServer ¶
type MockMCPServer struct {
// Function customization
StartFunc func(ctx context.Context) error
StopFunc func(ctx context.Context) error
RegisterToolsFunc func(tools []interface{}) error
RegisterResourcesFunc func(resources []interface{}) error
RegisterPromptsFunc func(prompts []interface{}) error
SetAuthProviderFunc func(provider interface{}) error
// Tracking fields
StartCalls int
StopCalls int
RegisterToolsCalls [][]interface{}
RegisterResourcesCalls [][]interface{}
RegisterPromptsCalls [][]interface{}
SetAuthProviderCalls []interface{}
// contains filtered or unexported fields
}
MockMCPServer provides a mock implementation of MCP server for testing.
func NewMockMCPServer ¶
func NewMockMCPServer() *MockMCPServer
NewMockMCPServer creates a new mock MCP server.
func (*MockMCPServer) RegisterPrompts ¶
func (m *MockMCPServer) RegisterPrompts(prompts []interface{}) error
RegisterPrompts implements MCPServer.RegisterPrompts
func (*MockMCPServer) RegisterResources ¶
func (m *MockMCPServer) RegisterResources(resources []interface{}) error
RegisterResources implements MCPServer.RegisterResources
func (*MockMCPServer) RegisterTools ¶
func (m *MockMCPServer) RegisterTools(tools []interface{}) error
RegisterTools implements MCPServer.RegisterTools
func (*MockMCPServer) SetAuthProvider ¶
func (m *MockMCPServer) SetAuthProvider(provider interface{}) error
SetAuthProvider implements MCPServer.SetAuthProvider
type MockMCPSession ¶
type MockMCPSession struct {
// Function customization
UserIDFunc func() string
OrganizationFunc func() string
PermissionsFunc func() []interface{}
AuditLogFunc func() interface{}
ConfigScopeFunc func() interface{}
// Tracking fields
UserIDCalls int
OrganizationCalls int
PermissionsCalls int
AuditLogCalls int
ConfigScopeCalls int
// contains filtered or unexported fields
}
MockMCPSession provides a mock implementation of MCP session for testing.
func NewMockMCPSession ¶
func NewMockMCPSession(userID, organization string) *MockMCPSession
NewMockMCPSession creates a new mock MCP session.
func (*MockMCPSession) AuditLog ¶
func (m *MockMCPSession) AuditLog() interface{}
AuditLog implements MCPSession.AuditLog
func (*MockMCPSession) ConfigScope ¶
func (m *MockMCPSession) ConfigScope() interface{}
ConfigScope implements MCPSession.ConfigScope
func (*MockMCPSession) Organization ¶
func (m *MockMCPSession) Organization() string
Organization implements MCPSession.Organization
func (*MockMCPSession) Permissions ¶
func (m *MockMCPSession) Permissions() []interface{}
Permissions implements MCPSession.Permissions
func (*MockMCPSession) UserID ¶
func (m *MockMCPSession) UserID() string
UserID implements MCPSession.UserID
type MockMigrationManager ¶
type MockMigrationManager struct {
// Function customization
MigrateConfigFunc func(cfg v2.Config, targetVersion string) (v2.Config, error)
GetCurrentVersionFunc func() string
GetSupportedVersionsFunc func() []string
ValidateMigrationPathFunc func(fromVersion, toVersion string) error
// Tracking fields
MigrateConfigCalls []MigrateConfigCall
GetCurrentVersionCalls int
GetSupportedVersionsCalls int
ValidateMigrationPathCalls []MigrationPathCall
// contains filtered or unexported fields
}
MockMigrationManager provides a mock implementation of migration manager for testing.
func NewMockMigrationManager ¶
func NewMockMigrationManager() *MockMigrationManager
NewMockMigrationManager creates a new mock migration manager.
func (*MockMigrationManager) GetCurrentVersion ¶
func (m *MockMigrationManager) GetCurrentVersion() string
GetCurrentVersion implements MigrationManager.GetCurrentVersion
func (*MockMigrationManager) GetSupportedVersions ¶
func (m *MockMigrationManager) GetSupportedVersions() []string
GetSupportedVersions implements MigrationManager.GetSupportedVersions
func (*MockMigrationManager) MigrateConfig ¶
func (m *MockMigrationManager) MigrateConfig(cfg v2.Config, targetVersion string) (v2.Config, error)
MigrateConfig implements MigrationManager.MigrateConfig
func (*MockMigrationManager) ValidateMigrationPath ¶
func (m *MockMigrationManager) ValidateMigrationPath(fromVersion, toVersion string) error
ValidateMigrationPath implements MigrationManager.ValidateMigrationPath
type MockServicePlugin ¶
type MockServicePlugin struct {
// Function customization
NameFunc func() string
TypeFunc func() string
ValidateFunc func(cfg v2.Config) error
RenderFunc func(ctx context.Context, cfg v2.Config, workspace interface{}) error
StatusFunc func(cfg v2.Config) interface{}
// Tracking fields
ValidateCalls []v2.Config
RenderCalls []RenderPluginCall
StatusCalls []v2.Config
// contains filtered or unexported fields
}
MockServicePlugin provides a mock implementation of service plugin for testing.
func NewMockServicePlugin ¶
func NewMockServicePlugin(name, pluginType string) *MockServicePlugin
NewMockServicePlugin creates a new mock service plugin.
func (*MockServicePlugin) Name ¶
func (m *MockServicePlugin) Name() string
Name implements ServicePlugin.Name
func (*MockServicePlugin) Status ¶
func (m *MockServicePlugin) Status(cfg v2.Config) interface{}
Status implements ServicePlugin.Status
func (*MockServicePlugin) Type ¶
func (m *MockServicePlugin) Type() string
Type implements ServicePlugin.Type
type MockServiceRegistry ¶
type MockServiceRegistry struct {
// Function customization
RegisterServiceFunc func(service interface{}) error
GetServiceFunc func(name string) (interface{}, error)
GetEnabledServicesFunc func(cfg v2.Config) []interface{}
ResolveDependenciesFunc func(services []string) ([]interface{}, error)
ValidateDependenciesFunc func(services []string) error
// Tracking fields
RegisterServiceCalls []interface{}
GetServiceCalls []string
GetEnabledServicesCalls []v2.Config
ResolveDependenciesCalls [][]string
ValidateDependenciesCalls [][]string
// contains filtered or unexported fields
}
MockServiceRegistry provides a mock implementation of service registry for testing.
func NewMockServiceRegistry ¶
func NewMockServiceRegistry() *MockServiceRegistry
NewMockServiceRegistry creates a new mock service registry.
func (*MockServiceRegistry) GetEnabledServices ¶
func (m *MockServiceRegistry) GetEnabledServices(cfg v2.Config) []interface{}
GetEnabledServices implements ServiceRegistry.GetEnabledServices
func (*MockServiceRegistry) GetService ¶
func (m *MockServiceRegistry) GetService(name string) (interface{}, error)
GetService implements ServiceRegistry.GetService
func (*MockServiceRegistry) RegisterService ¶
func (m *MockServiceRegistry) RegisterService(service interface{}) error
RegisterService implements ServiceRegistry.RegisterService
func (*MockServiceRegistry) ResolveDependencies ¶
func (m *MockServiceRegistry) ResolveDependencies(services []string) ([]interface{}, error)
ResolveDependencies implements ServiceRegistry.ResolveDependencies
func (*MockServiceRegistry) ValidateDependencies ¶
func (m *MockServiceRegistry) ValidateDependencies(services []string) error
ValidateDependencies implements ServiceRegistry.ValidateDependencies
type MockTemplateEngine ¶
type MockTemplateEngine struct {
// RenderFunc allows customizing the Render behavior
RenderFunc func(ctx context.Context, templatePath string, data interface{}) ([]byte, error)
// ValidateTemplateFunc allows customizing the ValidateTemplate behavior
ValidateTemplateFunc func(templatePath string) error
// RegisterFunctionFunc allows customizing the RegisterFunction behavior
RegisterFunctionFunc func(name string, fn interface{})
// SetCacheEnabledFunc allows customizing the SetCacheEnabled behavior
SetCacheEnabledFunc func(enabled bool)
// ClearCacheFunc allows customizing the ClearCache behavior
ClearCacheFunc func()
// Tracking fields for verification
RenderCalls []RenderCall
ValidateTemplateCalls []string
RegisteredFunctions map[string]interface{}
CacheEnabled bool
CacheClearCount int
// contains filtered or unexported fields
}
MockTemplateEngine provides a mock implementation of template.TemplateEngine for testing.
func NewMockTemplateEngine ¶
func NewMockTemplateEngine() *MockTemplateEngine
NewMockTemplateEngine creates a new mock template engine with default behaviors.
func (*MockTemplateEngine) ClearCache ¶
func (m *MockTemplateEngine) ClearCache()
ClearCache implements template.TemplateEngine.ClearCache
func (*MockTemplateEngine) RegisterFunction ¶
func (m *MockTemplateEngine) RegisterFunction(name string, fn interface{})
RegisterFunction implements template.TemplateEngine.RegisterFunction
func (*MockTemplateEngine) Render ¶
func (m *MockTemplateEngine) Render(ctx context.Context, templatePath string, data interface{}) ([]byte, error)
Render implements template.TemplateEngine.Render
func (*MockTemplateEngine) SetCacheEnabled ¶
func (m *MockTemplateEngine) SetCacheEnabled(enabled bool)
SetCacheEnabled implements template.TemplateEngine.SetCacheEnabled
func (*MockTemplateEngine) ValidateTemplate ¶
func (m *MockTemplateEngine) ValidateTemplate(templatePath string) error
ValidateTemplate implements template.TemplateEngine.ValidateTemplate
type MockTemplateRegistry ¶
type MockTemplateRegistry struct {
// Function customization
RegisterTemplateFunc func(template interface{}) error
GetTemplateFunc func(name string) (interface{}, error)
GetTemplatesForProviderFunc func(provider string) []interface{}
GetTemplatesForServiceFunc func(service string) []interface{}
GetTemplatesForEnabledServicesFunc func(enabledServices []string) []interface{}
GetTemplatesForTypeFunc func(templateType interface{}) []interface{}
ResolveTemplateDependenciesFunc func(templates []string) ([]interface{}, error)
ListTemplatesFunc func() []interface{}
UnregisterTemplateFunc func(name string) error
// Tracking fields
RegisterTemplateCalls []interface{}
GetTemplateCalls []string
GetTemplatesForProviderCalls []string
GetTemplatesForServiceCalls []string
GetTemplatesForEnabledServicesCalls [][]string
GetTemplatesForTypeCalls []interface{}
ResolveTemplateDependenciesCalls [][]string
ListTemplatesCalls int
UnregisterTemplateCalls []string
// contains filtered or unexported fields
}
MockTemplateRegistry provides a mock implementation of template registry for testing.
func NewMockTemplateRegistry ¶
func NewMockTemplateRegistry() *MockTemplateRegistry
NewMockTemplateRegistry creates a new mock template registry.
func (*MockTemplateRegistry) GetTemplate ¶
func (m *MockTemplateRegistry) GetTemplate(name string) (interface{}, error)
GetTemplate implements TemplateRegistry.GetTemplate
func (*MockTemplateRegistry) GetTemplatesForEnabledServices ¶
func (m *MockTemplateRegistry) GetTemplatesForEnabledServices(enabledServices []string) []interface{}
GetTemplatesForEnabledServices implements TemplateRegistry.GetTemplatesForEnabledServices
func (*MockTemplateRegistry) GetTemplatesForProvider ¶
func (m *MockTemplateRegistry) GetTemplatesForProvider(provider string) []interface{}
GetTemplatesForProvider implements TemplateRegistry.GetTemplatesForProvider
func (*MockTemplateRegistry) GetTemplatesForService ¶
func (m *MockTemplateRegistry) GetTemplatesForService(service string) []interface{}
GetTemplatesForService implements TemplateRegistry.GetTemplatesForService
func (*MockTemplateRegistry) GetTemplatesForType ¶
func (m *MockTemplateRegistry) GetTemplatesForType(templateType interface{}) []interface{}
GetTemplatesForType implements TemplateRegistry.GetTemplatesForType
func (*MockTemplateRegistry) ListTemplates ¶
func (m *MockTemplateRegistry) ListTemplates() []interface{}
ListTemplates implements TemplateRegistry.ListTemplates
func (*MockTemplateRegistry) RegisterTemplate ¶
func (m *MockTemplateRegistry) RegisterTemplate(template interface{}) error
RegisterTemplate implements TemplateRegistry.RegisterTemplate
func (*MockTemplateRegistry) ResolveTemplateDependencies ¶
func (m *MockTemplateRegistry) ResolveTemplateDependencies(templates []string) ([]interface{}, error)
ResolveTemplateDependencies implements TemplateRegistry.ResolveTemplateDependencies
func (*MockTemplateRegistry) UnregisterTemplate ¶
func (m *MockTemplateRegistry) UnregisterTemplate(name string) error
UnregisterTemplate implements TemplateRegistry.UnregisterTemplate
type NetworkingDataGenerator ¶
type NetworkingDataGenerator struct {
// contains filtered or unexported fields
}
NetworkingDataGenerator provides methods for generating realistic networking test data
func NewNetworkingDataGenerator ¶
func NewNetworkingDataGenerator(seed int64) *NetworkingDataGenerator
NewNetworkingDataGenerator creates a new networking data generator
func (*NetworkingDataGenerator) GenerateNetworkingConfig ¶
func (g *NetworkingDataGenerator) GenerateNetworkingConfig() map[string]interface{}
GenerateNetworkingConfig creates a realistic networking configuration for testing
type RenderCall ¶
type RenderCall struct {
TemplatePath string
Data interface{}
}
RenderCall tracks a call to Render
type RenderPluginCall ¶
RenderPluginCall tracks a call to Render
type ScenarioGenerator ¶
type ScenarioGenerator struct {
// contains filtered or unexported fields
}
ScenarioGenerator provides methods for generating complete realistic test scenarios
func NewScenarioGenerator ¶
func NewScenarioGenerator(seed int64) *ScenarioGenerator
NewScenarioGenerator creates a new scenario generator
func (*ScenarioGenerator) GenerateComplianceScenario ¶
func (g *ScenarioGenerator) GenerateComplianceScenario(provider string, framework string) map[string]interface{}
GenerateComplianceScenario creates scenarios for compliance testing
func (*ScenarioGenerator) GenerateDevelopmentScenario ¶
func (g *ScenarioGenerator) GenerateDevelopmentScenario(provider string) map[string]interface{}
GenerateDevelopmentScenario creates a realistic development cluster scenario
func (*ScenarioGenerator) GenerateDisasterRecoveryScenario ¶
func (g *ScenarioGenerator) GenerateDisasterRecoveryScenario(provider string) map[string]interface{}
GenerateDisasterRecoveryScenario creates a realistic DR scenario
func (*ScenarioGenerator) GenerateEdgeCaseScenario ¶
func (g *ScenarioGenerator) GenerateEdgeCaseScenario(provider string) map[string]interface{}
GenerateEdgeCaseScenario creates scenarios with edge cases for testing
func (*ScenarioGenerator) GenerateIntegrationTestScenario ¶
func (g *ScenarioGenerator) GenerateIntegrationTestScenario(provider string) map[string]interface{}
GenerateIntegrationTestScenario creates scenarios for integration testing
func (*ScenarioGenerator) GenerateMigrationScenario ¶
func (g *ScenarioGenerator) GenerateMigrationScenario(fromProvider, toProvider string) map[string]interface{}
GenerateMigrationScenario creates a realistic provider migration scenario
func (*ScenarioGenerator) GenerateMultiRegionScenario ¶
func (g *ScenarioGenerator) GenerateMultiRegionScenario(provider string) map[string]interface{}
GenerateMultiRegionScenario creates a realistic multi-region deployment scenario
func (*ScenarioGenerator) GeneratePerformanceTestScenario ¶
func (g *ScenarioGenerator) GeneratePerformanceTestScenario(provider string) map[string]interface{}
GeneratePerformanceTestScenario creates scenarios for performance testing
func (*ScenarioGenerator) GenerateProductionScenario ¶
func (g *ScenarioGenerator) GenerateProductionScenario(provider string) map[string]interface{}
GenerateProductionScenario creates a realistic production cluster scenario
func (*ScenarioGenerator) GenerateSecurityAuditScenario ¶
func (g *ScenarioGenerator) GenerateSecurityAuditScenario(provider string) map[string]interface{}
GenerateSecurityAuditScenario creates scenarios for security testing
func (*ScenarioGenerator) GenerateStagingScenario ¶
func (g *ScenarioGenerator) GenerateStagingScenario(provider string) map[string]interface{}
GenerateStagingScenario creates a realistic staging cluster scenario
func (*ScenarioGenerator) GenerateUpgradeScenario ¶
func (g *ScenarioGenerator) GenerateUpgradeScenario(provider string) map[string]interface{}
GenerateUpgradeScenario creates a realistic cluster upgrade scenario
type SecurityDataGenerator ¶
type SecurityDataGenerator struct {
// contains filtered or unexported fields
}
SecurityDataGenerator provides methods for generating realistic security test data
func NewSecurityDataGenerator ¶
func NewSecurityDataGenerator(seed int64) *SecurityDataGenerator
NewSecurityDataGenerator creates a new security data generator
func (*SecurityDataGenerator) GenerateSecurityConfig ¶
func (g *SecurityDataGenerator) GenerateSecurityConfig() map[string]interface{}
GenerateSecurityConfig creates a realistic security configuration for testing
type ServiceDataGenerator ¶
type ServiceDataGenerator struct {
// contains filtered or unexported fields
}
ServiceDataGenerator provides methods for generating realistic service test data
func NewServiceDataGenerator ¶
func NewServiceDataGenerator(seed int64) *ServiceDataGenerator
NewServiceDataGenerator creates a new service data generator
func (*ServiceDataGenerator) GenerateServiceDefinition ¶
func (g *ServiceDataGenerator) GenerateServiceDefinition() map[string]interface{}
GenerateServiceDefinition creates a realistic service definition for testing
type TemplateDataGenerator ¶
type TemplateDataGenerator struct {
// contains filtered or unexported fields
}
TemplateDataGenerator provides methods for generating realistic template test data
func NewTemplateDataGenerator ¶
func NewTemplateDataGenerator(seed int64) *TemplateDataGenerator
NewTemplateDataGenerator creates a new template data generator
func (*TemplateDataGenerator) GenerateTemplateData ¶
func (g *TemplateDataGenerator) GenerateTemplateData() map[string]interface{}
GenerateTemplateData creates realistic data for template rendering tests
type TestFramework ¶
type TestFramework struct {
// TempDir is the root temporary directory for test artifacts
TempDir string
// ConfigDir is the directory for test configuration files
ConfigDir string
// TemplateDir is the directory for test template files
TemplateDir string
// TemplateEngine is the template engine instance for tests
TemplateEngine template.TemplateEngine
// ConfigGenerator generates realistic test configurations
ConfigGenerator *ConfigGenerator
// TemplateDataGenerator generates realistic template test data
TemplateDataGenerator *TemplateDataGenerator
// ServiceDataGenerator generates realistic service test data
ServiceDataGenerator *ServiceDataGenerator
// GitOpsDataGenerator generates realistic GitOps test data
GitOpsDataGenerator *GitOpsDataGenerator
// Mock implementations for testing
MockTemplateEngine *MockTemplateEngine
MockConfigBuilder *MockConfigBuilder
MockConfigValidator *MockConfigValidator
MockTemplateRegistry *MockTemplateRegistry
MockGitOpsGenerator *MockGitOpsGenerator
MockServiceRegistry *MockServiceRegistry
MockMigrationManager *MockMigrationManager
MockMCPServer *MockMCPServer
MockAuthProvider *MockAuthProvider
MockErrorAggregator *MockErrorAggregator
// contains filtered or unexported fields
}
TestFramework provides a consistent testing environment for opencenter tests. It manages temporary directories, mock implementations, and test data generators.
Example ¶
ExampleTestFramework demonstrates how to use the test framework in your tests.
package main
import (
"context"
"testing"
testing_framework "github.com/opencenter-cloud/opencenter-cli/internal/testing"
)
func main() {
// This would normally be in a test function
t := &testing.T{}
// Create a new test framework
fw := testing_framework.NewTestFramework(t)
// Generate a test configuration
cfg := fw.CreateTestConfig("openstack")
// Use the configuration in your tests
_ = cfg.OpenCenter.Meta.Name
// Write a template for testing
templatePath := fw.WriteTemplate(t, "test.tmpl", "Hello {{ .Name }}!")
// Render the template
data := map[string]interface{}{"Name": "World"}
_, _ = fw.TemplateEngine.Render(context.Background(), templatePath, data)
// Assert files and directories exist
fw.AssertDirExists(t, fw.TempDir)
fw.AssertFileExists(t, templatePath)
}
Output:
func NewTestFramework ¶
func NewTestFramework(t *testing.T) *TestFramework
NewTestFramework creates a new test framework with a consistent environment. It sets up temporary directories, initializes generators, and registers cleanup.
func NewTestFrameworkWithSeed ¶
func NewTestFrameworkWithSeed(t *testing.T, seed int64) *TestFramework
NewTestFrameworkWithSeed creates a test framework with a custom seed for generators. This is useful when you need different random data in different tests.
Example ¶
ExampleNewTestFrameworkWithSeed demonstrates how to use the test framework with a custom seed.
package main
import (
"testing"
testing_framework "github.com/opencenter-cloud/opencenter-cli/internal/testing"
)
func main() {
t := &testing.T{}
// Create a test framework with a specific seed for reproducible tests
fw := testing_framework.NewTestFrameworkWithSeed(t, 12345)
// Generate deterministic test data
cfg := fw.CreateTestConfig("openstack")
_ = cfg.OpenCenter.Meta.Name
// Generate template data
templateData := fw.CreateTestTemplateData()
_ = templateData["ClusterName"]
// Generate service definition
service := fw.CreateTestServiceDefinition()
_ = service["name"]
// Generate GitOps config
gitops := fw.CreateTestGitOpsConfig()
_ = gitops["repository"]
}
Output:
func (*TestFramework) AssertDirExists ¶
func (fw *TestFramework) AssertDirExists(t *testing.T, path string)
AssertDirExists asserts that a directory exists at the given path.
func (*TestFramework) AssertDirNotExists ¶
func (fw *TestFramework) AssertDirNotExists(t *testing.T, path string)
AssertDirNotExists asserts that a directory does not exist at the given path.
func (*TestFramework) AssertFileExists ¶
func (fw *TestFramework) AssertFileExists(t *testing.T, path string)
AssertFileExists asserts that a file exists at the given path.
func (*TestFramework) AssertFileNotExists ¶
func (fw *TestFramework) AssertFileNotExists(t *testing.T, path string)
AssertFileNotExists asserts that a file does not exist at the given path.
func (*TestFramework) Cleanup ¶
func (fw *TestFramework) Cleanup()
Cleanup performs cleanup operations for the test framework. This is automatically called by testing.T.Cleanup() when using t.TempDir().
func (*TestFramework) CreateTestConfig ¶
func (fw *TestFramework) CreateTestConfig(provider string) v2.Config
CreateTestConfig creates a test configuration with the given provider.
func (*TestFramework) CreateTestGitOpsConfig ¶
func (fw *TestFramework) CreateTestGitOpsConfig() map[string]interface{}
CreateTestGitOpsConfig creates a test GitOps configuration.
func (*TestFramework) CreateTestServiceDefinition ¶
func (fw *TestFramework) CreateTestServiceDefinition() map[string]interface{}
CreateTestServiceDefinition creates a test service definition.
func (*TestFramework) CreateTestTemplateData ¶
func (fw *TestFramework) CreateTestTemplateData() map[string]interface{}
CreateTestTemplateData creates test data for template rendering.
func (*TestFramework) WriteFile ¶
WriteFile writes arbitrary content to a file in the temp directory. Returns the path to the written file.
func (*TestFramework) WriteTemplate ¶
WriteTemplate writes a template to a file in the test template directory. Returns the path to the written file.
type ValidatePermissionCall ¶
type ValidatePermissionCall struct {
Session interface{}
Permission interface{}
}
ValidatePermissionCall tracks a call to ValidatePermission
type WorkloadDataGenerator ¶
type WorkloadDataGenerator struct {
// contains filtered or unexported fields
}
WorkloadDataGenerator provides methods for generating realistic workload test data
func NewWorkloadDataGenerator ¶
func NewWorkloadDataGenerator(seed int64) *WorkloadDataGenerator
NewWorkloadDataGenerator creates a new workload data generator
func (*WorkloadDataGenerator) GenerateDeployment ¶
func (g *WorkloadDataGenerator) GenerateDeployment() map[string]interface{}
GenerateDeployment creates a realistic Kubernetes deployment for testing