framework

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// DefaultKindNodeImage is the default Kind node image
	DefaultKindNodeImage = "kindest/node:v1.32.0"
)
View Source
const (
	// RandomNamespacePrefix is the prefix for randomly generated namespace names
	RandomNamespacePrefix = "cosmopilot-test-"
)
View Source
const VaultCredsSecretName = "vault-creds"

VaultCredsSecretName is the name of the secret containing Vault root credentials

Variables

View Source
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

func RandString(n int) string

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) Cancel

func (b *BaseFramework) Cancel()

Cancel cancels the context

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

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

func WithCSIDriver(install bool) Option

WithCSIDriver sets whether to install CSI hostpath driver (for e2e)

func WithCertManager

func WithCertManager(install bool) Option

WithCertManager sets whether to install cert-manager (for e2e)

func WithCertsDir

func WithCertsDir(dir string) Option

WithCertsDir sets the certificates directory

func WithChartVersion

func WithChartVersion(version string) Option

WithChartVersion sets the helm chart version (for e2e release mode)

func WithClusterName

func WithClusterName(name string) Option

WithClusterName sets the Kind cluster name (for e2e)

func WithControllerImage

func WithControllerImage(image string) Option

WithControllerImage sets the controller image (for e2e)

func WithIngressNginx

func WithIngressNginx(install bool) Option

WithIngressNginx sets whether to install ingress-nginx (for e2e)

func WithIssuerName

func WithIssuerName(name string) Option

WithIssuerName sets the cert-manager issuer name

func WithNodeUtilsImage

func WithNodeUtilsImage(image string) Option

WithNodeUtilsImage sets the node-utils image

func WithReuseCluster

func WithReuseCluster(reuse bool) Option

WithReuseCluster sets whether to reuse an existing cluster (for e2e)

func WithVault

func WithVault(install bool) Option

WithVault sets whether to install HashiCorp Vault (for e2e)

func WithWorkerCount

func WithWorkerCount(count int) Option

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

Jump to

Keyboard shortcuts

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