testutil

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseVersion   = "26.3.22.7"
	UpdateVersion = "26.7.5.10"
)
View Source
const (
	// PollInterval is the default polling interval for Eventually-style waits.
	PollInterval = 100 * time.Millisecond
)

Variables

This section is empty.

Functions

func CheckPodReady added in v0.0.8

func CheckPodReady(pod *corev1.Pod) bool

CheckPodReady returns true when the pod's Ready condition is true.

func CurrentSpecHash added in v0.0.4

func CurrentSpecHash() string

CurrentSpecHash returns a stable hash for the currently running Ginkgo spec.

func DumpNamespaceDiagnostics added in v0.0.4

func DumpNamespaceDiagnostics(ctx context.Context, env *Env, ns, dir string)

DumpNamespaceDiagnostics dumps resources, pod logs and events from namespace.

func EnsureNamespace added in v0.0.4

func EnsureNamespace(ctx context.Context, env *Env, name string)

EnsureNamespace ensures the test namespace is created and active.

func EnsureTestNamespace added in v0.0.8

func EnsureTestNamespace(ctx context.Context, env *Env) string

EnsureTestNamespace ensures that unique per test namespace is created and returns its name.

func GetProjectDir

func GetProjectDir() (string, error)

GetProjectDir will return the directory where the project is by walking up from the current working directory until it finds a go.mod file.

func InstallCRDs added in v0.0.4

func InstallCRDs(ctx context.Context) error

InstallCRDs installs the CRDs into the cluster using make install.

func InstallCertManager

func InstallCertManager(ctx context.Context) error

InstallCertManager installs the cert manager bundle.

func InstallNetworkPolicyController added in v0.0.8

func InstallNetworkPolicyController(ctx context.Context) error

InstallNetworkPolicyController installs kube-network-policies so the default kind CNI enforces NetworkPolicies.

func MustRun added in v0.0.6

func MustRun(ctx context.Context, name string, args ...string) error

MustRun executes the provided command and fails the test if it returns an error.

func NewPortForwardDialer added in v0.0.4

func NewPortForwardDialer(config *rest.Config) controllerutil.DialContextFunc

NewPortForwardDialer returns a DialContextFunc that connects to pods inside a Kubernetes cluster by creating SPDY port-forward streams through the API server. It resolves both Pod and Service hostnames to their target Pod.

func PreloadImages added in v0.0.4

func PreloadImages(ctx context.Context, images []string) *errgroup.Group

PreloadImages pulls each image from the registry and loads it into the kind cluster. All images are processed in parallel.

func Run

func Run(cmd *exec.Cmd) ([]byte, error)

Run executes the provided command within this context.

func SetupCA

func SetupCA(ctx context.Context, k8sClient client.Client, namespace string, suffix uint32)

SetupCA sets up a self-signed CA issuer and a CA certificate in the given namespace.

func TestNamespace added in v0.0.8

func TestNamespace() string

TestNamespace returns the deterministic namespace name unique for every test.

func UninstallCRDs added in v0.0.4

func UninstallCRDs(ctx context.Context) error

UninstallCRDs removes the CRDs from the cluster using make uninstall.

Types

type ClickHouseBuilder added in v0.0.8

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

ClickHouseBuilder assembles a ClickHouseCluster CR for tests. Defaults: 1 replica, image tag BaseVersion.

func NewClickHouseCluster added in v0.0.8

func NewClickHouseCluster(namespace, name string) *ClickHouseBuilder

NewClickHouseCluster returns a builder for a minimal valid cluster.

func (*ClickHouseBuilder) Cluster added in v0.0.8

func (b *ClickHouseBuilder) Cluster() v1.ClickHouseCluster

Cluster returns the assembled CR.

func (*ClickHouseBuilder) WithContainerTemplate added in v0.0.8

func (b *ClickHouseBuilder) WithContainerTemplate(template v1.ContainerTemplateSpec) *ClickHouseBuilder

WithContainerTemplate replaces the container template wholesale, keeping the image tag.

func (*ClickHouseBuilder) WithKeeper added in v0.0.8

func (b *ClickHouseBuilder) WithKeeper(name string) *ClickHouseBuilder

WithKeeper sets the KeeperCluster reference.

func (*ClickHouseBuilder) WithNetworkPolicy added in v0.0.8

func (b *ClickHouseBuilder) WithNetworkPolicy(policy v1.NetworkPolicyPolicy) *ClickHouseBuilder

WithNetworkPolicy sets the managed NetworkPolicy mode.

func (*ClickHouseBuilder) WithPodTemplate added in v0.0.8

func (b *ClickHouseBuilder) WithPodTemplate(template v1.PodTemplateSpec) *ClickHouseBuilder

WithPodTemplate sets the pod template.

func (*ClickHouseBuilder) WithReplicas added in v0.0.8

func (b *ClickHouseBuilder) WithReplicas(replicas int32) *ClickHouseBuilder

WithReplicas sets the replica count.

func (*ClickHouseBuilder) WithShards added in v0.0.8

func (b *ClickHouseBuilder) WithShards(shards int32) *ClickHouseBuilder

WithShards sets the shard count.

func (*ClickHouseBuilder) WithStorage added in v0.0.8

WithStorage sets the data volume claim spec.

func (*ClickHouseBuilder) WithTag added in v0.0.8

func (b *ClickHouseBuilder) WithTag(tag string) *ClickHouseBuilder

WithTag sets the image tag.

type ClickHouseClient

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

ClickHouseClient is a ClickHouse client for testing ClickHouse clusters.

func NewClickHouseClient

func NewClickHouseClient(
	ctx context.Context,
	dialer controllerutil.DialContextFunc,
	cr *v1.ClickHouseCluster,
	auth ...clickhouse.Auth,
) (*ClickHouseClient, error)

NewClickHouseClient creates a new ClickHouseClient connected to the specified ClickHouseCluster.

func (*ClickHouseClient) CheckDefaultDatabasesReplicated

func (c *ClickHouseClient) CheckDefaultDatabasesReplicated(ctx context.Context) error

CheckDefaultDatabasesReplicated checks that the default database has Replicated engine on all cluster nodes.

func (*ClickHouseClient) CheckRead

func (c *ClickHouseClient) CheckRead(ctx context.Context, order int) error

CheckRead reads and verifies test data from the ClickHouse cluster.

func (*ClickHouseClient) CheckWrite

func (c *ClickHouseClient) CheckWrite(ctx context.Context, order int) error

CheckWrite writes test data to the ClickHouse cluster.

func (*ClickHouseClient) Close

func (c *ClickHouseClient) Close()

Close closes the ClickHouseClient and releases all resources.

func (*ClickHouseClient) CreateDatabase

func (c *ClickHouseClient) CreateDatabase(ctx context.Context) error

CreateDatabase creates the test database on the ClickHouse cluster.

func (*ClickHouseClient) Exec added in v0.0.3

func (c *ClickHouseClient) Exec(ctx context.Context, query string, args ...any) error

Exec executes a query on one of the ClickHouse cluster nodes.

func (*ClickHouseClient) ExecReplica added in v0.0.8

func (c *ClickHouseClient) ExecReplica(
	ctx context.Context,
	id v1.ClickHouseReplicaID,
	query string,
	args ...any,
) error

ExecReplica executes a query on the specified ClickHouse replica.

func (*ClickHouseClient) Query added in v0.0.3

func (c *ClickHouseClient) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)

Query executes a query on one of the ClickHouse cluster nodes.

func (*ClickHouseClient) QueryRow

func (c *ClickHouseClient) QueryRow(ctx context.Context, query string, result any) error

QueryRow executes a query on one of the ClickHouse cluster nodes. Scans the result into the provided result variable.

func (*ClickHouseClient) QueryRowReplica added in v0.0.6

func (c *ClickHouseClient) QueryRowReplica(
	ctx context.Context,
	id v1.ClickHouseReplicaID,
	query string,
	result any,
) error

QueryRowReplica executes a query on one of the ClickHouse cluster nodes. Scans the result into the provided result variable.

type DumpResult added in v0.0.4

type DumpResult struct {
	Short string
	Full  string
}

DumpResult holds a short summary and the full dump content.

func (*DumpResult) Empty added in v0.0.4

func (d *DumpResult) Empty() bool

Empty returns true if no data dumped.

func (*DumpResult) WriteFull added in v0.0.4

func (d *DumpResult) WriteFull(dir, filename string) (string, error)

WriteFull writes the full dump to a file inside dir and returns the file path.

type Env added in v0.0.8

type Env struct {
	Client client.Client
	Config *rest.Config
	Dialer controllerutil.DialContextFunc
	// contains filtered or unexported fields
}

Env bundles the suite-level handles shared by the test helpers.

func SetupEnv added in v0.0.8

func SetupEnv(opts SetupOptions) *Env

SetupEnv resolves kubeconfig, registers schemes and builds the suite Env.

func (*Env) Cache added in v0.0.8

func (e *Env) Cache() cache.Cache

Cache lazily starts a suite-lifetime informer cache and returns it. Register StopCache as a suite cleanup after the goroutine-leak assertion.

func (*Env) ClickHouseRWChecks added in v0.0.8

func (e *Env) ClickHouseRWChecks(
	ctx context.Context, cr *v1.ClickHouseCluster, checksDone *int, auth ...clickhouse.Auth,
)

ClickHouseRWChecks writes a new data batch and reads back all batches written so far.

func (*Env) KeeperRWChecks added in v0.0.8

func (e *Env) KeeperRWChecks(ctx context.Context, cr *v1.KeeperCluster, checksDone *int)

KeeperRWChecks writes a new data batch and reads back all batches written so far.

func (*Env) ProbePhase added in v0.0.8

func (e *Env) ProbePhase(ctx context.Context, pod *corev1.Pod) func(Gomega) corev1.PodPhase

ProbePhase polls the probe pod phase for Eventually assertions.

func (*Env) RunConnectivityProbe added in v0.0.8

func (e *Env) RunConnectivityProbe(
	ctx context.Context, ns, name, target string, port int, podLabels map[string]string,
) *corev1.Pod

RunConnectivityProbe starts a pod that checks TCP connectivity to the target once.

func (*Env) StopCache added in v0.0.8

func (e *Env) StopCache()

StopCache stops the informer cache and waits for its goroutines to exit.

func (*Env) WaitClickHouseUpdatedAndReady added in v0.0.8

func (e *Env) WaitClickHouseUpdatedAndReady(ctx context.Context, cr *v1.ClickHouseCluster, timeout time.Duration)

WaitClickHouseUpdatedAndReady waits until the cluster rollout completes and all replicas are ready.

func (*Env) WaitDeploymentAvailable added in v0.0.8

func (e *Env) WaitDeploymentAvailable(ctx context.Context, namespace, name string, timeout time.Duration)

WaitDeploymentAvailable waits until the deployment rollout completes and it reports Available.

func (*Env) WaitKeeperUpdatedAndReady added in v0.0.8

func (e *Env) WaitKeeperUpdatedAndReady(ctx context.Context, cr *v1.KeeperCluster, timeout time.Duration)

WaitKeeperUpdatedAndReady waits until the keeper rollout completes and all replicas are ready.

type Invariant added in v0.0.8

type Invariant interface {
	Name() string
	Check(ctx context.Context, namespace string) []Violation
}

Invariant represents a single cluster property that should not be violated during the cluster lifetime.

type InvariantSet added in v0.0.8

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

InvariantSet enforces invariants in a background goroutine for one spec.

func StartInvariants added in v0.0.8

func StartInvariants(env *Env, namespace string) *InvariantSet

StartInvariants launches background enforcement of all invariants; absence of violations is asserted in DeferCleanup.

func (*InvariantSet) StopAndCheck added in v0.0.8

func (s *InvariantSet) StopAndCheck()

StopAndCheck stops enforcement and fails the spec on recorded violations; extra calls are no-ops.

type KeeperBuilder added in v0.0.8

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

KeeperBuilder assembles a KeeperCluster CR for tests. Defaults: 1 replica, image tag BaseVersion.

func NewKeeperCluster added in v0.0.8

func NewKeeperCluster(namespace, name string) *KeeperBuilder

NewKeeperCluster returns a builder for a minimal valid keeper.

func (*KeeperBuilder) Cluster added in v0.0.8

func (b *KeeperBuilder) Cluster() v1.KeeperCluster

Cluster returns the assembled CR.

func (*KeeperBuilder) WithContainerTemplate added in v0.0.8

func (b *KeeperBuilder) WithContainerTemplate(template v1.ContainerTemplateSpec) *KeeperBuilder

WithContainerTemplate replaces the container template wholesale, keeping the image tag.

func (*KeeperBuilder) WithNetworkPolicy added in v0.0.8

func (b *KeeperBuilder) WithNetworkPolicy(policy v1.NetworkPolicyPolicy) *KeeperBuilder

WithNetworkPolicy sets the managed NetworkPolicy mode.

func (*KeeperBuilder) WithPodTemplate added in v0.0.8

func (b *KeeperBuilder) WithPodTemplate(template v1.PodTemplateSpec) *KeeperBuilder

WithPodTemplate sets the pod template.

func (*KeeperBuilder) WithReplicas added in v0.0.8

func (b *KeeperBuilder) WithReplicas(replicas int32) *KeeperBuilder

WithReplicas sets the replica count.

func (*KeeperBuilder) WithSettings added in v0.0.8

func (b *KeeperBuilder) WithSettings(settings v1.KeeperSettings) *KeeperBuilder

WithSettings sets the keeper settings.

func (*KeeperBuilder) WithStorage added in v0.0.8

WithStorage sets the data volume claim spec.

func (*KeeperBuilder) WithTag added in v0.0.8

func (b *KeeperBuilder) WithTag(tag string) *KeeperBuilder

WithTag sets the image tag.

type KeeperClient

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

KeeperClient is a ZooKeeper client for testing Keeper clusters.

func NewKeeperClient

func NewKeeperClient(
	ctx context.Context, dialer controllerutil.DialContextFunc, cr *v1.KeeperCluster,
) (*KeeperClient, error)

NewKeeperClient creates a new KeeperClient connected to the specified KeeperCluster.

func (*KeeperClient) CheckRead

func (c *KeeperClient) CheckRead(order int) error

CheckRead reads and verifies test data from the Keeper cluster.

func (*KeeperClient) CheckWrite

func (c *KeeperClient) CheckWrite(order int) error

CheckWrite writes test data to the Keeper cluster.

func (*KeeperClient) Close

func (c *KeeperClient) Close()

Close closes the KeeperClient and releases all resources.

type SetupOptions added in v0.0.8

type SetupOptions struct {
	// CertManagerScheme registers cert-manager types into the scheme.
	CertManagerScheme bool
	// RequireExplicitImageTag rejects cluster CR creation without an image tag.
	RequireExplicitImageTag bool
}

SetupOptions configures the shared suite bootstrap.

type ShardingConfig added in v0.0.8

type ShardingConfig struct {
	Index    int    `env:"E2E_SHARD_INDEX, default=0"`
	Total    int    `env:"E2E_SHARD_TOTAL, default=0"`
	PlanPath string `env:"E2E_SHARD_PLAN"`
	// contains filtered or unexported fields
}

ShardingConfig assigns specs to CI shards from a pre-computed plan.

func (*ShardingConfig) Enabled added in v0.0.8

func (c *ShardingConfig) Enabled(spec string) (bool, error)

Enabled reports whether the given spec belongs to this shard.

func (*ShardingConfig) Load added in v0.0.8

func (c *ShardingConfig) Load() error

Load reads the sharding configuration from the environment and the plan file.

type Violation added in v0.0.8

type Violation struct {
	Time      time.Time
	Invariant string
	Object    string
	Message   string
	Warning   bool
}

Violation is a single invariant breach observed during a spec.

func (Violation) String added in v0.0.8

func (v Violation) String() string

Jump to

Keyboard shortcuts

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