Documentation
¶
Index ¶
- Constants
- Variables
- func RandString(n int) string
- type BaseFramework
- func (b *BaseFramework) Cancel()
- func (b *BaseFramework) Client() client.Client
- func (b *BaseFramework) Config() *Config
- func (b *BaseFramework) Context() context.Context
- func (b *BaseFramework) CreateRandomNamespace() (*corev1.Namespace, error)
- func (b *BaseFramework) DeleteNamespace(ns *corev1.Namespace) error
- func (b *BaseFramework) KubeClient() *kubernetes.Clientset
- func (b *BaseFramework) PodExec(namespace, podName, container string, command ...string) (string, error)
- func (b *BaseFramework) RestConfig() *rest.Config
- func (b *BaseFramework) RunAppCommand(namespace, image, appBinary, accountSecretName string, args []string) (string, error)
- func (b *BaseFramework) SetClient(c client.Client)
- func (b *BaseFramework) SetConfig(cfg *Config)
- func (b *BaseFramework) SetContext(ctx context.Context, cancel context.CancelFunc)
- func (b *BaseFramework) SetKubeClient(c *kubernetes.Clientset)
- func (b *BaseFramework) SetRestConfig(cfg *rest.Config)
- type Config
- type EnvTestFramework
- type Framework
- type FrameworkType
- type KindFramework
- func (f *KindFramework) CreateClusterIssuer(name string) error
- func (f *KindFramework) DeployController() error
- func (f *KindFramework) LoadImage(image string) error
- func (f *KindFramework) Provider() *cluster.Provider
- func (f *KindFramework) Setup(ctx context.Context) error
- func (f *KindFramework) TearDown() error
- func (f *KindFramework) Type() FrameworkType
- func (f *KindFramework) UndeployController() error
- type Option
- func WithCSIDriver(install bool) Option
- func WithCertManager(install bool) Option
- func WithCertsDir(dir string) Option
- func WithChartVersion(version string) Option
- func WithClusterName(name string) Option
- func WithControllerImage(image string) Option
- func WithIngressNginx(install bool) Option
- func WithIssuerName(name string) Option
- func WithNodeUtilsImage(image string) Option
- func WithReuseCluster(reuse bool) Option
- func WithVault(install bool) Option
- func WithWorkerCount(count int) Option
- type TestHelpers
- func (h *TestHelpers) CreateConfigMap(namespace, name string, data map[string]string) error
- func (h *TestHelpers) CreateSecret(namespace, name string, data map[string][]byte) error
- func (h *TestHelpers) CreateVolumeSnapshotClass(name, driver string) error
- func (h *TestHelpers) SimulateCertificateReady(namespace, secretName string, dnsNames []string) error
- func (h *TestHelpers) SimulateSnapshotReady(namespace, snapshotName string, restoreSize string) error
- func (h *TestHelpers) WaitForPodReady(namespace, name string, timeout time.Duration) error
Constants ¶
const ( // VaultNamespace is the namespace where Vault is deployed VaultNamespace = "vault-system" // VaultTokenSecretName is the name of the secret containing the Vault token for TMKMS VaultTokenSecretName = "vault-tmkms-token" // VaultCASecretName is the name of the secret containing the Vault CA certificate VaultCASecretName = "vault-tls" // VaultAddress returns the in-cluster Vault address VaultAddress = "https://vault.vault-system.svc.cluster.local:8200" )
const (
// DefaultKindNodeImage is the default Kind node image
DefaultKindNodeImage = "kindest/node:v1.32.0"
)
const (
// RandomNamespacePrefix is the prefix for randomly generated namespace names
RandomNamespacePrefix = "cosmopilot-test-"
)
const VaultCredsSecretName = "vault-creds"
VaultCredsSecretName is the name of the secret containing Vault root credentials
Variables ¶
var ( // CRDsPath is the path to the CRD files CRDsPath = filepath.Join("..", "..", "helm", "cosmopilot", "crds") // ExternalCRDsPath is the path to external CRD files (cert-manager, volumesnapshot) ExternalCRDsPath = filepath.Join("..", "..", "test", "testdata", "crds") // WebhooksPath is the path to webhook configuration files for envtest WebhooksPath = filepath.Join("..", "..", "test", "testdata", "webhooks") )
Functions ¶
func RandString ¶
RandString generates a random string of the specified length
Types ¶
type BaseFramework ¶
type BaseFramework struct {
// contains filtered or unexported fields
}
BaseFramework contains common functionality for all framework implementations
func (*BaseFramework) Client ¶
func (b *BaseFramework) Client() client.Client
Client returns the controller-runtime client
func (*BaseFramework) Config ¶
func (b *BaseFramework) Config() *Config
Config returns the framework configuration
func (*BaseFramework) Context ¶
func (b *BaseFramework) Context() context.Context
Context returns the framework context
func (*BaseFramework) CreateRandomNamespace ¶
func (b *BaseFramework) CreateRandomNamespace() (*corev1.Namespace, error)
CreateRandomNamespace creates a namespace with a random name
func (*BaseFramework) DeleteNamespace ¶
func (b *BaseFramework) DeleteNamespace(ns *corev1.Namespace) error
DeleteNamespace deletes the given namespace
func (*BaseFramework) KubeClient ¶
func (b *BaseFramework) KubeClient() *kubernetes.Clientset
KubeClient returns the kubernetes clientset
func (*BaseFramework) PodExec ¶
func (b *BaseFramework) PodExec(namespace, podName, container string, command ...string) (string, error)
PodExec executes a command in a pod container and returns stdout
func (*BaseFramework) RestConfig ¶
func (b *BaseFramework) RestConfig() *rest.Config
RestConfig returns the REST config
func (*BaseFramework) RunAppCommand ¶
func (b *BaseFramework) RunAppCommand(namespace, image, appBinary, accountSecretName string, args []string) (string, error)
RunAppCommand creates a temporary pod with the account secret mounted and runs a command. This is useful for running app CLI commands that require the validator account (e.g., submitting transactions). The mnemonic is imported into the keyring before running the command using the app binary only (no shell required).
func (*BaseFramework) SetClient ¶
func (b *BaseFramework) SetClient(c client.Client)
SetClient sets the controller-runtime client
func (*BaseFramework) SetConfig ¶
func (b *BaseFramework) SetConfig(cfg *Config)
SetConfig sets the configuration
func (*BaseFramework) SetContext ¶
func (b *BaseFramework) SetContext(ctx context.Context, cancel context.CancelFunc)
SetContext sets the context and cancel function
func (*BaseFramework) SetKubeClient ¶
func (b *BaseFramework) SetKubeClient(c *kubernetes.Clientset)
SetKubeClient sets the kubernetes clientset
func (*BaseFramework) SetRestConfig ¶
func (b *BaseFramework) SetRestConfig(cfg *rest.Config)
SetRestConfig sets the REST config
type Config ¶
type Config struct {
// CertsDir is the directory containing webhook certificates
CertsDir string
// IssuerName is the cert-manager ClusterIssuer name
IssuerName string
// WorkerCount is the number of controller workers
WorkerCount int
// NodeUtilsImage is the node-utils image to use
NodeUtilsImage string
// ControllerImage is the controller image (for e2e only)
ControllerImage string
// ChartVersion is the helm chart version to deploy (for e2e release mode)
// If set, deploys from OCI registry instead of local chart
ChartVersion string
// ClusterName is the Kind cluster name (for e2e only)
ClusterName string
// ReuseCluster indicates whether to reuse an existing cluster (for e2e only)
ReuseCluster bool
// InstallCertManager indicates whether to install cert-manager (for e2e only)
InstallCertManager bool
// InstallCSIDriver indicates whether to install CSI hostpath driver (for e2e only)
InstallCSIDriver bool
// InstallIngressNginx indicates whether to install ingress-nginx (for e2e only)
InstallIngressNginx bool
// InstallVault indicates whether to install HashiCorp Vault (for e2e only)
InstallVault bool
}
Config holds configuration for test frameworks
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with default values
type EnvTestFramework ¶
type EnvTestFramework struct {
BaseFramework
// contains filtered or unexported fields
}
EnvTestFramework implements Framework using controller-runtime's envtest
func NewEnvTestFramework ¶
func NewEnvTestFramework(opts ...Option) *EnvTestFramework
NewEnvTestFramework creates a new envtest-based framework
func (*EnvTestFramework) Env ¶
func (f *EnvTestFramework) Env() *envtest.Environment
Env returns the underlying envtest environment
func (*EnvTestFramework) Setup ¶
func (f *EnvTestFramework) Setup(ctx context.Context) error
Setup initializes the envtest environment
func (*EnvTestFramework) StartManager ¶
func (f *EnvTestFramework) StartManager() error
StartManager starts the controller manager
func (*EnvTestFramework) StopManager ¶
func (f *EnvTestFramework) StopManager()
StopManager stops the controller manager
func (*EnvTestFramework) TearDown ¶
func (f *EnvTestFramework) TearDown() error
TearDown cleans up the envtest environment
func (*EnvTestFramework) Type ¶
func (f *EnvTestFramework) Type() FrameworkType
Type returns the framework type
type Framework ¶
type Framework interface {
// Setup initializes the test framework
Setup(ctx context.Context) error
// TearDown cleans up the test framework
TearDown() error
// Context returns the context used by the framework
Context() context.Context
// Client returns the controller-runtime client
Client() client.Client
// KubeClient returns the kubernetes clientset
KubeClient() *kubernetes.Clientset
// RestConfig returns the REST config for the cluster
RestConfig() *rest.Config
// Config returns the framework configuration
Config() *Config
// CreateRandomNamespace creates a namespace with a random name
CreateRandomNamespace() (*corev1.Namespace, error)
// DeleteNamespace deletes the given namespace
DeleteNamespace(ns *corev1.Namespace) error
// PodExec executes a command in a pod container and returns stdout
PodExec(namespace, podName, container string, command ...string) (string, error)
// RunAppCommand creates a temporary pod with the account secret mounted and runs a command
RunAppCommand(namespace, image, appBinary, accountSecretName, command string) (string, error)
// Type returns the type of framework (integration or e2e)
Type() FrameworkType
}
Framework defines the interface for test frameworks. Both integration (envtest) and e2e (Kind) frameworks implement this interface.
type FrameworkType ¶
type FrameworkType string
FrameworkType identifies the type of test framework
const ( // FrameworkTypeIntegration is for envtest-based integration tests FrameworkTypeIntegration FrameworkType = "integration" // FrameworkTypeE2E is for Kind-based e2e tests FrameworkTypeE2E FrameworkType = "e2e" )
type KindFramework ¶
type KindFramework struct {
BaseFramework
// contains filtered or unexported fields
}
KindFramework implements Framework using Kind clusters
func NewKindFramework ¶
func NewKindFramework(opts ...Option) *KindFramework
NewKindFramework creates a new Kind-based framework
func (*KindFramework) CreateClusterIssuer ¶
func (f *KindFramework) CreateClusterIssuer(name string) error
CreateClusterIssuer creates a self-signed ClusterIssuer
func (*KindFramework) DeployController ¶
func (f *KindFramework) DeployController() error
DeployController deploys the controller to the cluster using Helm. If ChartVersion is set, deploys from OCI registry (release mode). Otherwise, deploys from local chart with ControllerImage (dev mode).
func (*KindFramework) LoadImage ¶
func (f *KindFramework) LoadImage(image string) error
LoadImage loads a Docker image into the Kind cluster
func (*KindFramework) Provider ¶
func (f *KindFramework) Provider() *cluster.Provider
Provider returns the Kind provider
func (*KindFramework) Setup ¶
func (f *KindFramework) Setup(ctx context.Context) error
Setup initializes the Kind cluster and installs dependencies
func (*KindFramework) TearDown ¶
func (f *KindFramework) TearDown() error
TearDown cleans up the Kind cluster
func (*KindFramework) Type ¶
func (f *KindFramework) Type() FrameworkType
Type returns the framework type
func (*KindFramework) UndeployController ¶
func (f *KindFramework) UndeployController() error
UndeployController removes the controller from the cluster
type Option ¶
type Option func(*Config)
Option is a function that modifies the Config
func WithCSIDriver ¶
WithCSIDriver sets whether to install CSI hostpath driver (for e2e)
func WithCertManager ¶
WithCertManager sets whether to install cert-manager (for e2e)
func WithCertsDir ¶
WithCertsDir sets the certificates directory
func WithChartVersion ¶
WithChartVersion sets the helm chart version (for e2e release mode)
func WithClusterName ¶
WithClusterName sets the Kind cluster name (for e2e)
func WithControllerImage ¶
WithControllerImage sets the controller image (for e2e)
func WithIngressNginx ¶
WithIngressNginx sets whether to install ingress-nginx (for e2e)
func WithIssuerName ¶
WithIssuerName sets the cert-manager issuer name
func WithNodeUtilsImage ¶
WithNodeUtilsImage sets the node-utils image
func WithReuseCluster ¶
WithReuseCluster sets whether to reuse an existing cluster (for e2e)
func WithWorkerCount ¶
WithWorkerCount sets the number of controller workers
type TestHelpers ¶
type TestHelpers struct {
// contains filtered or unexported fields
}
TestHelpers provides helper methods for testing
func NewTestHelpers ¶
func NewTestHelpers(c client.Client, ctx context.Context) *TestHelpers
NewTestHelpers creates a new TestHelpers instance
func (*TestHelpers) CreateConfigMap ¶
func (h *TestHelpers) CreateConfigMap(namespace, name string, data map[string]string) error
CreateConfigMap creates a ConfigMap
func (*TestHelpers) CreateSecret ¶
func (h *TestHelpers) CreateSecret(namespace, name string, data map[string][]byte) error
CreateSecret creates a generic secret
func (*TestHelpers) CreateVolumeSnapshotClass ¶
func (h *TestHelpers) CreateVolumeSnapshotClass(name, driver string) error
CreateVolumeSnapshotClass creates a VolumeSnapshotClass for testing
func (*TestHelpers) SimulateCertificateReady ¶
func (h *TestHelpers) SimulateCertificateReady(namespace, secretName string, dnsNames []string) error
SimulateCertificateReady simulates cert-manager creating a TLS secret for a Certificate This is useful for integration tests where cert-manager is not running
func (*TestHelpers) SimulateSnapshotReady ¶
func (h *TestHelpers) SimulateSnapshotReady(namespace, snapshotName string, restoreSize string) error
SimulateSnapshotReady simulates a VolumeSnapshot becoming ready This is useful for integration tests where the CSI driver is not running
func (*TestHelpers) WaitForPodReady ¶
func (h *TestHelpers) WaitForPodReady(namespace, name string, timeout time.Duration) error
WaitForPodReady waits for a pod to be ready