Documentation
¶
Index ¶
- type BaseTestImplementation
- func (b *BaseTestImplementation) CreateTestNode(ctx context.Context, nodeConfig *TestNodeConfig) (*v1.Node, error)
- func (b *BaseTestImplementation) CreateTestRoute(ctx context.Context, routeConfig *TestRouteConfig) (*cloudprovider.Route, error)
- func (b *BaseTestImplementation) CreateTestService(ctx context.Context, serviceConfig *TestServiceConfig) (*v1.Service, error)
- func (b *BaseTestImplementation) DeleteTestNode(ctx context.Context, nodeName string) error
- func (b *BaseTestImplementation) DeleteTestRoute(ctx context.Context, routeName string) error
- func (b *BaseTestImplementation) DeleteTestService(ctx context.Context, serviceName string) error
- func (b *BaseTestImplementation) GetCloudProvider() cloudprovider.Interface
- func (b *BaseTestImplementation) GetTestResults() *TestResults
- func (b *BaseTestImplementation) ResetTestState() error
- func (b *BaseTestImplementation) SetupTestEnvironment(config *TestConfig) error
- func (b *BaseTestImplementation) TeardownTestEnvironment() error
- func (b *BaseTestImplementation) WaitForCondition(ctx context.Context, condition TestCondition) error
- type FakeTestImplementation
- type MockClientBuilder
- type Test
- type TestCondition
- type TestConfig
- type TestInterface
- type TestNodeConfig
- type TestResult
- type TestResults
- type TestRouteConfig
- type TestRunner
- type TestServiceConfig
- type TestSuite
- type TestSummary
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseTestImplementation ¶
type BaseTestImplementation struct {
// CloudProvider is the cloud provider instance being tested.
CloudProvider cloudprovider.Interface
// ClientBuilder is the client builder for creating Kubernetes clients.
ClientBuilder cloudprovider.ControllerClientBuilder
// InformerFactory is the informer factory for creating informers.
InformerFactory informers.SharedInformerFactory
// TestConfig holds the current test configuration.
TestConfig *TestConfig
// TestResults holds the current test results.
TestResults *TestResults
// CreatedResources tracks resources created during tests for cleanup.
CreatedResources map[string][]string
// contains filtered or unexported fields
}
BaseTestImplementation provides a base implementation of the TestInterface that can be extended by specific cloud provider test implementations.
func NewBaseTestImplementation ¶
func NewBaseTestImplementation(cloudProvider cloudprovider.Interface) *BaseTestImplementation
NewBaseTestImplementation creates a new base test implementation.
func (*BaseTestImplementation) CreateTestNode ¶
func (b *BaseTestImplementation) CreateTestNode(ctx context.Context, nodeConfig *TestNodeConfig) (*v1.Node, error)
CreateTestNode creates a test node.
func (*BaseTestImplementation) CreateTestRoute ¶
func (b *BaseTestImplementation) CreateTestRoute(ctx context.Context, routeConfig *TestRouteConfig) (*cloudprovider.Route, error)
CreateTestRoute creates a test route.
func (*BaseTestImplementation) CreateTestService ¶
func (b *BaseTestImplementation) CreateTestService(ctx context.Context, serviceConfig *TestServiceConfig) (*v1.Service, error)
CreateTestService creates a test service.
func (*BaseTestImplementation) DeleteTestNode ¶
func (b *BaseTestImplementation) DeleteTestNode(ctx context.Context, nodeName string) error
DeleteTestNode deletes a test node.
func (*BaseTestImplementation) DeleteTestRoute ¶
func (b *BaseTestImplementation) DeleteTestRoute(ctx context.Context, routeName string) error
DeleteTestRoute deletes a test route.
func (*BaseTestImplementation) DeleteTestService ¶
func (b *BaseTestImplementation) DeleteTestService(ctx context.Context, serviceName string) error
DeleteTestService deletes a test service.
func (*BaseTestImplementation) GetCloudProvider ¶
func (b *BaseTestImplementation) GetCloudProvider() cloudprovider.Interface
GetCloudProvider returns the cloud provider instance.
func (*BaseTestImplementation) GetTestResults ¶
func (b *BaseTestImplementation) GetTestResults() *TestResults
GetTestResults returns the test results.
func (*BaseTestImplementation) ResetTestState ¶
func (b *BaseTestImplementation) ResetTestState() error
ResetTestState resets the test state.
func (*BaseTestImplementation) SetupTestEnvironment ¶
func (b *BaseTestImplementation) SetupTestEnvironment(config *TestConfig) error
SetupTestEnvironment initializes the test environment.
func (*BaseTestImplementation) TeardownTestEnvironment ¶
func (b *BaseTestImplementation) TeardownTestEnvironment() error
TeardownTestEnvironment cleans up the test environment.
func (*BaseTestImplementation) WaitForCondition ¶
func (b *BaseTestImplementation) WaitForCondition(ctx context.Context, condition TestCondition) error
WaitForCondition waits for a specific condition to be met.
type FakeTestImplementation ¶
type FakeTestImplementation struct {
*BaseTestImplementation
FakeCloud *fakecloud.Cloud
}
FakeTestImplementation provides a test implementation using the fake cloud provider. This is useful for testing the test framework itself or for cloud providers that want to use the fake provider for testing.
func NewFakeTestImplementation ¶
func NewFakeTestImplementation() *FakeTestImplementation
NewFakeTestImplementation creates a new fake test implementation.
func (*FakeTestImplementation) GetFakeCloud ¶
func (f *FakeTestImplementation) GetFakeCloud() *fakecloud.Cloud
GetFakeCloud returns the fake cloud provider instance.
type MockClientBuilder ¶
type MockClientBuilder struct {
ConfigFunc func(name string) (*rest.Config, error)
ClientFunc func(name string) (clientset.Interface, error)
ConfigOrDieFunc func(name string) *rest.Config
ClientOrDieFunc func(name string) clientset.Interface
}
MockClientBuilder provides a mock implementation of ControllerClientBuilder for testing.
func (*MockClientBuilder) Client ¶
func (m *MockClientBuilder) Client(name string) (clientset.Interface, error)
Client implements ControllerClientBuilder.Client.
func (*MockClientBuilder) ClientOrDie ¶
func (m *MockClientBuilder) ClientOrDie(name string) clientset.Interface
ClientOrDie implements ControllerClientBuilder.ClientOrDie.
func (*MockClientBuilder) Config ¶
func (m *MockClientBuilder) Config(name string) (*rest.Config, error)
Config implements ControllerClientBuilder.Config.
func (*MockClientBuilder) ConfigOrDie ¶
func (m *MockClientBuilder) ConfigOrDie(name string) *rest.Config
ConfigOrDie implements ControllerClientBuilder.ConfigOrDie.
type Test ¶
type Test struct {
// Name is the name of the test.
Name string
// Description is the description of the test.
Description string
// Run is the function that runs the test.
Run func(TestInterface) error
// Skip determines whether to skip this test.
Skip bool
// SkipReason is the reason for skipping the test.
SkipReason string
// Timeout is the timeout for the test.
Timeout time.Duration
// Dependencies are the dependencies required for the test.
Dependencies []string
// Cleanup is the cleanup function for the test.
Cleanup func(TestInterface) error
}
Test defines a single test that can be run against a cloud provider.
type TestCondition ¶
type TestCondition struct {
// Type is the type of the condition.
Type string
// Status is the status of the condition.
Status string
// Reason is the reason for the condition.
Reason string
// Message is the message of the condition.
Message string
// Timeout is the timeout for the condition.
Timeout time.Duration
// CheckFunction is a custom function to check the condition.
CheckFunction func() (bool, error)
}
TestCondition represents a condition that should be met during testing.
type TestConfig ¶
type TestConfig struct {
// ProviderName is the name of the cloud provider being tested.
ProviderName string
// ClusterName is the name of the test cluster.
ClusterName string
// Region is the region where the test resources should be created.
Region string
// Zone is the zone where the test resources should be created.
Zone string
// ClientBuilder is the client builder for creating Kubernetes clients.
ClientBuilder cloudprovider.ControllerClientBuilder
// InformerFactory is the informer factory for creating informers.
InformerFactory informers.SharedInformerFactory
// TestTimeout is the timeout for test operations.
TestTimeout time.Duration
// CleanupResources determines whether to clean up resources after tests.
CleanupResources bool
// MockExternalServices determines whether to use mock external services.
MockExternalServices bool
// TestData contains additional test-specific configuration.
TestData map[string]interface{}
}
TestConfig holds the configuration for a test environment.
type TestInterface ¶
type TestInterface interface {
// SetupTestEnvironment initializes the test environment with the given configuration.
// This should create any necessary test resources, mock services, or test data.
SetupTestEnvironment(config *TestConfig) error
// TeardownTestEnvironment cleans up the test environment and removes any test resources.
TeardownTestEnvironment() error
// GetCloudProvider returns the cloud provider instance to be tested.
// This allows the test framework to access the actual cloud provider implementation.
GetCloudProvider() cloudprovider.Interface
// CreateTestNode creates a test node with the specified configuration.
// The node should be created in a way that simulates a real node in the cloud provider.
CreateTestNode(ctx context.Context, nodeConfig *TestNodeConfig) (*v1.Node, error)
// DeleteTestNode deletes a test node.
DeleteTestNode(ctx context.Context, nodeName string) error
// CreateTestService creates a test service with the specified configuration.
// The service should be created in a way that simulates a real service in the cloud provider.
CreateTestService(ctx context.Context, serviceConfig *TestServiceConfig) (*v1.Service, error)
// DeleteTestService deletes a test service.
DeleteTestService(ctx context.Context, serviceName string) error
// CreateTestRoute creates a test route with the specified configuration.
CreateTestRoute(ctx context.Context, routeConfig *TestRouteConfig) (*cloudprovider.Route, error)
// DeleteTestRoute deletes a test route.
DeleteTestRoute(ctx context.Context, routeName string) error
WaitForCondition(ctx context.Context, condition TestCondition) error
// GetTestResults returns the results of the test execution.
GetTestResults() *TestResults
// ResetTestState resets the test state to a clean state.
ResetTestState() error
}
TestInterface is an abstract, pluggable interface for testing cloud providers. This interface provides a cloud-agnostic way to test cloud provider implementations by abstracting away the specific cloud provider details and focusing on the behavior and functionality that should be consistent across all cloud providers.
type TestNodeConfig ¶
type TestNodeConfig struct {
// Name is the name of the test node.
Name string
// ProviderID is the provider ID of the node.
ProviderID string
// InstanceType is the instance type of the node.
InstanceType string
// Zone is the zone where the node should be created.
Zone string
// Region is the region where the node should be created.
Region string
// Addresses are the network addresses of the node.
Addresses []v1.NodeAddress
// Labels are the labels to be applied to the node.
Labels map[string]string
// Annotations are the annotations to be applied to the node.
Annotations map[string]string
// Conditions are the conditions of the node.
Conditions []v1.NodeCondition
}
TestNodeConfig holds the configuration for creating a test node.
type TestResult ¶
type TestResult struct {
// Test is the test that was run.
Test Test
// Success indicates whether the test was successful.
Success bool
// Error is the error that occurred during the test.
Error error
// Duration is the duration of the test.
Duration time.Duration
// StartTime is the start time of the test.
StartTime time.Time
// EndTime is the end time of the test.
EndTime time.Time
}
TestResult holds the result of a single test.
type TestResults ¶
type TestResults struct {
// Success indicates whether the test was successful.
Success bool
// Error is the error that occurred during the test.
Error error
// Duration is the duration of the test.
Duration time.Duration
// ResourceCounts contains counts of resources created during the test.
ResourceCounts map[string]int
// Metrics contains test-specific metrics.
Metrics map[string]interface{}
// Logs contains test logs.
Logs []string
// contains filtered or unexported fields
}
TestResults holds the results of a test execution.
func (*TestResults) AddLog ¶
func (tr *TestResults) AddLog(log string)
AddLog adds a log entry to the test results.
func (*TestResults) IncrementResourceCount ¶
func (tr *TestResults) IncrementResourceCount(resourceType string)
IncrementResourceCount increments the count for a resource type.
func (*TestResults) SetMetric ¶
func (tr *TestResults) SetMetric(key string, value interface{})
SetMetric sets a metric in the test results.
type TestRouteConfig ¶
type TestRouteConfig struct {
// Name is the name of the test route.
Name string
// ClusterName is the name of the cluster.
ClusterName string
// TargetNode is the target node for the route.
TargetNode types.NodeName
// DestinationCIDR is the destination CIDR for the route.
DestinationCIDR string
// Blackhole determines whether this is a blackhole route.
Blackhole bool
}
TestRouteConfig holds the configuration for creating a test route.
type TestRunner ¶
type TestRunner struct {
// TestInterface is the test interface to use.
TestInterface TestInterface
// TestSuites are the test suites to run.
TestSuites []TestSuite
// Results are the results of the test execution.
Results []TestResult
// contains filtered or unexported fields
}
TestRunner is responsible for running tests against cloud providers.
Example ¶
ExampleTestRunner demonstrates how to use the TestRunner to run tests.
// Create a fake test implementation
fakeImpl := NewFakeTestImplementation()
// Create a test runner
runner := NewTestRunner(fakeImpl)
// Add test suites
runner.AddTestSuite(CreateExampleTestSuite())
// Run tests
ctx := context.Background()
err := runner.RunTests(ctx)
if err != nil {
fmt.Printf("Test execution failed: %v\n", err)
return
}
// Get results
results := runner.GetResults()
summary := runner.GetSummary()
fmt.Printf("Test Summary:\n")
fmt.Printf(" Total Tests: %d\n", summary.TotalTests)
fmt.Printf(" Passed: %d\n", summary.PassedTests)
fmt.Printf(" Failed: %d\n", summary.FailedTests)
fmt.Printf(" Skipped: %d\n", summary.SkippedTests)
fmt.Printf(" Duration: %v\n", summary.TotalDuration)
// Print detailed results
for _, result := range results {
status := "PASSED"
if !result.Success {
status = "FAILED"
}
if result.Test.Skip {
status = "SKIPPED"
}
fmt.Printf(" %s: %s (%v)\n", status, result.Test.Name, result.Duration)
}
func NewTestRunner ¶
func NewTestRunner(testInterface TestInterface) *TestRunner
NewTestRunner creates a new test runner.
func (*TestRunner) AddTestSuite ¶
func (tr *TestRunner) AddTestSuite(suite TestSuite)
AddTestSuite adds a test suite to the test runner.
func (*TestRunner) GetResults ¶
func (tr *TestRunner) GetResults() []TestResult
GetResults returns the results of the test execution.
func (*TestRunner) GetSummary ¶
func (tr *TestRunner) GetSummary() TestSummary
GetSummary returns a summary of the test results.
type TestServiceConfig ¶
type TestServiceConfig struct {
// Name is the name of the test service.
Name string
// Namespace is the namespace of the service.
Namespace string
// Type is the type of the service.
Type v1.ServiceType
// Ports are the ports of the service.
Ports []v1.ServicePort
// LoadBalancerIP is the IP address for the load balancer.
LoadBalancerIP string
// ExternalTrafficPolicy is the external traffic policy.
ExternalTrafficPolicy v1.ServiceExternalTrafficPolicy
// InternalTrafficPolicy is the internal traffic policy.
InternalTrafficPolicy *v1.ServiceInternalTrafficPolicy
// Labels are the labels to be applied to the service.
Labels map[string]string
// Annotations are the annotations to be applied to the service.
Annotations map[string]string
}
TestServiceConfig holds the configuration for creating a test service.
type TestSuite ¶
type TestSuite struct {
// Name is the name of the test suite.
Name string
// Description is the description of the test suite.
Description string
// Tests is the list of tests in the suite.
Tests []Test
// Setup is the setup function for the test suite.
Setup func(TestInterface) error
// Teardown is the teardown function for the test suite.
Teardown func(TestInterface) error
// Dependencies are the dependencies required for the test suite.
Dependencies []string
}
TestSuite defines a collection of tests that can be run against a cloud provider.
type TestSummary ¶
type TestSummary struct {
// TotalTests is the total number of tests run.
TotalTests int
// PassedTests is the number of tests that passed.
PassedTests int
// FailedTests is the number of tests that failed.
FailedTests int
// SkippedTests is the number of tests that were skipped.
SkippedTests int
// TotalDuration is the total duration of all tests.
TotalDuration time.Duration
}
TestSummary holds a summary of test results.