testutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContainerNotFound = errors.New("container not found")
	ErrDockerOperation   = errors.New("docker operation failed")
)

Common test errors

Functions

func AnalyticsSchema

func AnalyticsSchema() string

AnalyticsSchema returns a test analytics database schema

func BasicClickHouseConfig

func BasicClickHouseConfig() string

BasicClickHouseConfig returns a basic ClickHouse configuration for testing

func ComplexDictionarySchema

func ComplexDictionarySchema() string

ComplexDictionarySchema returns a test dictionary with complex configuration

func ContainerWithMigrations

func ContainerWithMigrations(t *testing.T, fixture *ProjectFixture, migrations []MigrationFile) (*docker.ClickHouseContainer, string)

ContainerWithMigrations creates a container and applies the given migrations

func CreateTestCommand

func CreateTestCommand(name string, action func(context.Context, *cli.Command) error) *cli.Command

CreateTestCommand creates a simple test command for testing purposes

func CreateTestCommandWithFlags

func CreateTestCommandWithFlags(name string, flags []cli.Flag, action func(context.Context, *cli.Command) error) *cli.Command

CreateTestCommandWithFlags creates a test command with flags

func CreateTestContainer

func CreateTestContainer(t *testing.T, version, configDir, name string) *docker.ClickHouseContainer

CreateTestContainer creates a test container with custom options

func DatabasesSchema

func DatabasesSchema() string

DatabasesSchema returns a schema file with database definitions

func DefaultConfig

func DefaultConfig() *config.Config

DefaultConfig returns a default configuration for testing

func DefaultSchema

func DefaultSchema() string

DefaultSchema returns a standard test schema

func EventsTableSchema

func EventsTableSchema() string

EventsTableSchema returns a test events table schema

func MaterializedViewSchema

func MaterializedViewSchema() string

MaterializedViewSchema returns a test materialized view schema

func ParseCommandFlags

func ParseCommandFlags(t *testing.T, command *cli.Command, args []string) (*cli.Command, error)

ParseCommandFlags parses command line flags for a command

func ReplicatedTableSchema

func ReplicatedTableSchema() string

ReplicatedTableSchema returns a test replicated table schema

func RequireClickHouseXMLValid

func RequireClickHouseXMLValid(t *testing.T, xmlPath string, expectedCluster string)

RequireClickHouseXMLValid asserts that a ClickHouse XML config is valid

func RequireConfigValid

func RequireConfigValid(t *testing.T, configPath string, checks ...func(content string))

RequireConfigValid asserts that a housekeeper.yaml file is valid

func RequireDirEmpty

func RequireDirEmpty(t *testing.T, dirPath string)

RequireDirEmpty asserts that a directory is empty

func RequireDirNotEmpty

func RequireDirNotEmpty(t *testing.T, dirPath string)

RequireDirNotEmpty asserts that a directory is not empty

func RequireDockerAvailable

func RequireDockerAvailable(t *testing.T)

RequireDockerAvailable ensures Docker is available or fails the test

func RequireError

func RequireError(t *testing.T, err error, msgContains ...string)

RequireError asserts that an error occurred and optionally checks the message

func RequireFileContains

func RequireFileContains(t *testing.T, expected string) func(string)

RequireFileContains returns a check function that verifies file contains text

func RequireFileExists

func RequireFileExists(t *testing.T, path string, checks ...func(content string))

RequireFileExists asserts that a file exists and optionally checks its content

func RequireFileNotContains

func RequireFileNotContains(t *testing.T, unexpected string) func(string)

RequireFileNotContains returns a check function that verifies file doesn't contain text

func RequireFilePermissions

func RequireFilePermissions(t *testing.T, path string, expectedMode os.FileMode)

RequireFilePermissions asserts that a file has specific permissions

func RequireMigrationCount

func RequireMigrationCount(t *testing.T, migrationsDir string, expectedCount int)

RequireMigrationCount asserts that a specific number of migrations exist

func RequireMigrationValid

func RequireMigrationValid(t *testing.T, migrationPath string)

RequireMigrationValid asserts that a migration file is valid SQL

func RequireNoDir

func RequireNoDir(t *testing.T, path string)

RequireNoDir asserts that a directory does not exist

func RequireNoError

func RequireNoError(t *testing.T, err error, msg ...string)

RequireNoError asserts that no error occurred

func RequireNoFile

func RequireNoFile(t *testing.T, path string)

RequireNoFile asserts that a file does not exist

func RequireSchemaEqual

func RequireSchemaEqual(t *testing.T, expected, actual string)

RequireSchemaEqual asserts that two SQL schemas are functionally equivalent

func RequireSumFileValid

func RequireSumFileValid(t *testing.T, sumPath string)

RequireSumFileValid asserts that a sum file exists and has valid format

func RequireValidProject

func RequireValidProject(t *testing.T, projectDir string)

RequireValidProject asserts that a project structure is correctly initialized

func RunCommand

func RunCommand(t *testing.T, command *cli.Command, args []string) error

RunCommand executes a command with test context

func RunCommandWithContext

func RunCommandWithContext(ctx context.Context, t *testing.T, command *cli.Command, args []string) error

RunCommandWithContext executes a command with a custom context

func SchemaWithImports

func SchemaWithImports() string

SchemaWithImports returns a schema file with import directives

func SetupClickHouseContainer

func SetupClickHouseContainer(t *testing.T, configDir string) *docker.ClickHouseContainer

SetupClickHouseContainer creates a ClickHouse container for testing

func SkipIfNoDocker

func SkipIfNoDocker(t *testing.T)

SkipIfNoDocker skips the test if Docker is not available

func StartClickHouseContainer

func StartClickHouseContainer(t *testing.T, configDir string) (*docker.ClickHouseContainer, string)

StartClickHouseContainer starts a ClickHouse container and returns it

func TestClickHouseXMLConfig

func TestClickHouseXMLConfig(cluster string) string

TestClickHouseXMLConfig returns a test ClickHouse XML configuration

func TestCommandExecution

func TestCommandExecution(t *testing.T, command *cli.Command, args []string) error

TestCommandExecution runs a command and verifies it executes without error

func TestCommandExecutionWithError

func TestCommandExecutionWithError(t *testing.T, command *cli.Command, args []string) error

TestCommandExecutionWithError runs a command and returns the error

func TestHousekeeperYAMLConfig

func TestHousekeeperYAMLConfig(cluster, version, configDir string) string

TestHousekeeperYAMLConfig returns a test housekeeper.yaml configuration

func TestSumFileContent

func TestSumFileContent() string

TestSumFileContent returns a sample sum file content

func UsersTableSchema

func UsersTableSchema() string

UsersTableSchema returns a test users table schema

func WaitForClickHouse

func WaitForClickHouse(ctx context.Context, dsn string, maxRetries int) error

WaitForClickHouse waits for ClickHouse to be ready

Types

type MigrationFile

type MigrationFile struct {
	Version string
	SQL     string
}

MigrationFile represents a test migration

func EmptyMigration

func EmptyMigration() MigrationFile

EmptyMigration returns an empty but valid migration

func GenerateTimestampedMigration

func GenerateTimestampedMigration(name, sql string) MigrationFile

GenerateTimestampedMigration creates a migration with current timestamp

func InvalidMigration

func InvalidMigration() MigrationFile

InvalidMigration returns a migration with invalid SQL

func MinimalMigrations

func MinimalMigrations() []MigrationFile

MinimalMigrations returns a minimal set of migrations for basic testing

func SampleMigrations

func SampleMigrations() []MigrationFile

SampleMigrations returns common test migrations

type MockClickHouseContainer

type MockClickHouseContainer struct {
	GetDSNFunc     func(ctx context.Context) (string, error)
	GetHTTPDSNFunc func(ctx context.Context) (string, error)
	StartFunc      func(ctx context.Context) error
	StopFunc       func(ctx context.Context) error
	IsRunningFunc  func() bool
}

MockClickHouseContainer creates a mock ClickHouse container for testing

func NewMockClickHouseContainer

func NewMockClickHouseContainer() *MockClickHouseContainer

NewMockClickHouseContainer creates a new mock ClickHouse container with default implementations

func (*MockClickHouseContainer) GetDSN

GetDSN implements the ClickHouseContainer interface

func (*MockClickHouseContainer) GetHTTPDSN

func (m *MockClickHouseContainer) GetHTTPDSN(ctx context.Context) (string, error)

GetHTTPDSN implements the ClickHouseContainer interface

func (*MockClickHouseContainer) IsRunning

func (m *MockClickHouseContainer) IsRunning() bool

IsRunning implements the ClickHouseContainer interface

func (*MockClickHouseContainer) Start

Start implements the ClickHouseContainer interface

func (*MockClickHouseContainer) Stop

Stop implements the ClickHouseContainer interface

type MockDockerClient

type MockDockerClient struct {
	ImagePullFunc        func(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
	ContainerCreateFunc  func(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *v1.Platform, containerName string) (container.CreateResponse, error)
	ContainerStartFunc   func(ctx context.Context, containerID string, options container.StartOptions) error
	ContainerListFunc    func(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
	ContainerStopFunc    func(ctx context.Context, containerID string, options container.StopOptions) error
	ContainerRemoveFunc  func(ctx context.Context, containerID string, options container.RemoveOptions) error
	ContainerInspectFunc func(ctx context.Context, containerID string) (container.InspectResponse, error)
}

MockDockerClient creates a mock Docker client for testing that implements docker.DockerClient

func NewMockDockerClient

func NewMockDockerClient() *MockDockerClient

NewMockDockerClient creates a new mock Docker client with default implementations

func (*MockDockerClient) ContainerCreate

func (m *MockDockerClient) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *v1.Platform, containerName string) (container.CreateResponse, error)

ContainerCreate implements docker.DockerClient interface

func (*MockDockerClient) ContainerInspect

func (m *MockDockerClient) ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)

ContainerInspect implements docker.DockerClient interface

func (*MockDockerClient) ContainerList

func (m *MockDockerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)

ContainerList implements docker.DockerClient interface

func (*MockDockerClient) ContainerRemove

func (m *MockDockerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error

ContainerRemove implements docker.DockerClient interface

func (*MockDockerClient) ContainerStart

func (m *MockDockerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error

ContainerStart implements docker.DockerClient interface

func (*MockDockerClient) ContainerStop

func (m *MockDockerClient) ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error

ContainerStop implements docker.DockerClient interface

func (*MockDockerClient) ImagePull

func (m *MockDockerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)

ImagePull implements docker.DockerClient interface

type ProjectFixture

type ProjectFixture struct {
	Dir       string
	Config    *config.Config
	Project   *project.Project
	Formatter *format.Formatter
	// contains filtered or unexported fields
}

ProjectFixture represents a test project environment with all necessary dependencies

func TestProject

func TestProject(t *testing.T) *ProjectFixture

TestProject creates an isolated temp directory with initialized housekeeper project

func (*ProjectFixture) Cleanup

func (p *ProjectFixture) Cleanup()

Cleanup removes all test resources (automatically handled by t.TempDir())

func (*ProjectFixture) GetConfigPath

func (p *ProjectFixture) GetConfigPath() string

GetConfigPath returns the path to the housekeeper.yaml file

func (*ProjectFixture) GetMainSchemaPath

func (p *ProjectFixture) GetMainSchemaPath() string

GetMainSchemaPath returns the path to the main schema file

func (*ProjectFixture) GetMigrationsDir

func (p *ProjectFixture) GetMigrationsDir() string

GetMigrationsDir returns the path to the migrations directory

func (*ProjectFixture) GetSchemasDir

func (p *ProjectFixture) GetSchemasDir() string

GetSchemasDir returns the path to the schemas directory

func (*ProjectFixture) WithClickHouseCluster

func (p *ProjectFixture) WithClickHouseCluster(cluster string) *ProjectFixture

WithClickHouseCluster sets the ClickHouse cluster in the config

func (*ProjectFixture) WithClickHouseConfigDir

func (p *ProjectFixture) WithClickHouseConfigDir(configDir string) *ProjectFixture

WithClickHouseConfigDir sets the ClickHouse config directory in the config

func (*ProjectFixture) WithClickHouseVersion

func (p *ProjectFixture) WithClickHouseVersion(version string) *ProjectFixture

WithClickHouseVersion sets the ClickHouse version in the config

func (*ProjectFixture) WithConfig

func (p *ProjectFixture) WithConfig(cfg TestConfig) *ProjectFixture

WithConfig updates the project configuration with custom settings

func (*ProjectFixture) WithMigrations

func (p *ProjectFixture) WithMigrations(migrations []MigrationFile) *ProjectFixture

WithMigrations adds migration files to the project

func (*ProjectFixture) WithSchema

func (p *ProjectFixture) WithSchema(schemaSQL string) *ProjectFixture

WithSchema sets the main schema content

func (*ProjectFixture) WithSchemaFiles

func (p *ProjectFixture) WithSchemaFiles(files map[string]string) *ProjectFixture

WithSchemaFiles adds additional schema files to the project

func (*ProjectFixture) WithSumFile

func (p *ProjectFixture) WithSumFile(content string) *ProjectFixture

WithSumFile creates a sum file for the migrations

type TestConfig

type TestConfig struct {
	Cluster   string
	Version   string
	ConfigDir string
}

TestConfig represents test configuration options

Jump to

Keyboard shortcuts

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