Documentation
¶
Index ¶
- Variables
- func AnalyticsSchema() string
- func BasicClickHouseConfig() string
- func ComplexDictionarySchema() string
- func ContainerWithMigrations(t *testing.T, fixture *ProjectFixture, migrations []MigrationFile) (*docker.ClickHouseContainer, string)
- func CreateTestCommand(name string, action func(context.Context, *cli.Command) error) *cli.Command
- func CreateTestCommandWithFlags(name string, flags []cli.Flag, ...) *cli.Command
- func CreateTestContainer(t *testing.T, version, configDir, name string) *docker.ClickHouseContainer
- func DatabasesSchema() string
- func DefaultConfig() *config.Config
- func DefaultSchema() string
- func EventsTableSchema() string
- func MaterializedViewSchema() string
- func ParseCommandFlags(t *testing.T, command *cli.Command, args []string) (*cli.Command, error)
- func ReplicatedTableSchema() string
- func RequireClickHouseXMLValid(t *testing.T, xmlPath string, expectedCluster string)
- func RequireConfigValid(t *testing.T, configPath string, checks ...func(content string))
- func RequireDirEmpty(t *testing.T, dirPath string)
- func RequireDirNotEmpty(t *testing.T, dirPath string)
- func RequireDockerAvailable(t *testing.T)
- func RequireError(t *testing.T, err error, msgContains ...string)
- func RequireFileContains(t *testing.T, expected string) func(string)
- func RequireFileExists(t *testing.T, path string, checks ...func(content string))
- func RequireFileNotContains(t *testing.T, unexpected string) func(string)
- func RequireFilePermissions(t *testing.T, path string, expectedMode os.FileMode)
- func RequireMigrationCount(t *testing.T, migrationsDir string, expectedCount int)
- func RequireMigrationValid(t *testing.T, migrationPath string)
- func RequireNoDir(t *testing.T, path string)
- func RequireNoError(t *testing.T, err error, msg ...string)
- func RequireNoFile(t *testing.T, path string)
- func RequireSchemaEqual(t *testing.T, expected, actual string)
- func RequireSumFileValid(t *testing.T, sumPath string)
- func RequireValidProject(t *testing.T, projectDir string)
- func RunCommand(t *testing.T, command *cli.Command, args []string) error
- func RunCommandWithContext(ctx context.Context, t *testing.T, command *cli.Command, args []string) error
- func SchemaWithImports() string
- func SetupClickHouseContainer(t *testing.T, configDir string) *docker.ClickHouseContainer
- func SkipIfNoDocker(t *testing.T)
- func StartClickHouseContainer(t *testing.T, configDir string) (*docker.ClickHouseContainer, string)
- func TestClickHouseXMLConfig(cluster string) string
- func TestCommandExecution(t *testing.T, command *cli.Command, args []string) error
- func TestCommandExecutionWithError(t *testing.T, command *cli.Command, args []string) error
- func TestHousekeeperYAMLConfig(cluster, version, configDir string) string
- func TestSumFileContent() string
- func UsersTableSchema() string
- func WaitForClickHouse(ctx context.Context, dsn string, maxRetries int) error
- type MigrationFile
- type MockClickHouseContainer
- func (m *MockClickHouseContainer) GetDSN(ctx context.Context) (string, error)
- func (m *MockClickHouseContainer) GetHTTPDSN(ctx context.Context) (string, error)
- func (m *MockClickHouseContainer) IsRunning() bool
- func (m *MockClickHouseContainer) Start(ctx context.Context) error
- func (m *MockClickHouseContainer) Stop(ctx context.Context) error
- type MockDockerClient
- func (m *MockDockerClient) ContainerCreate(ctx context.Context, config *container.Config, ...) (container.CreateResponse, error)
- func (m *MockDockerClient) ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
- func (m *MockDockerClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
- func (m *MockDockerClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
- func (m *MockDockerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error
- func (m *MockDockerClient) ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error
- func (m *MockDockerClient) ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
- type ProjectFixture
- func (p *ProjectFixture) Cleanup()
- func (p *ProjectFixture) GetConfigPath() string
- func (p *ProjectFixture) GetMainSchemaPath() string
- func (p *ProjectFixture) GetMigrationsDir() string
- func (p *ProjectFixture) GetSchemasDir() string
- func (p *ProjectFixture) WithClickHouseCluster(cluster string) *ProjectFixture
- func (p *ProjectFixture) WithClickHouseConfigDir(configDir string) *ProjectFixture
- func (p *ProjectFixture) WithClickHouseVersion(version string) *ProjectFixture
- func (p *ProjectFixture) WithConfig(cfg TestConfig) *ProjectFixture
- func (p *ProjectFixture) WithMigrations(migrations []MigrationFile) *ProjectFixture
- func (p *ProjectFixture) WithSchema(schemaSQL string) *ProjectFixture
- func (p *ProjectFixture) WithSchemaFiles(files map[string]string) *ProjectFixture
- func (p *ProjectFixture) WithSumFile(content string) *ProjectFixture
- type TestConfig
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
DefaultConfig returns a default configuration for testing
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 ¶
ParseCommandFlags parses command line flags for a command
func ReplicatedTableSchema ¶
func ReplicatedTableSchema() string
ReplicatedTableSchema returns a test replicated table schema
func RequireClickHouseXMLValid ¶
RequireClickHouseXMLValid asserts that a ClickHouse XML config is valid
func RequireConfigValid ¶
RequireConfigValid asserts that a housekeeper.yaml file is valid
func RequireDirEmpty ¶
RequireDirEmpty asserts that a directory is empty
func RequireDirNotEmpty ¶
RequireDirNotEmpty asserts that a directory is not empty
func RequireDockerAvailable ¶
RequireDockerAvailable ensures Docker is available or fails the test
func RequireError ¶
RequireError asserts that an error occurred and optionally checks the message
func RequireFileContains ¶
RequireFileContains returns a check function that verifies file contains text
func RequireFileExists ¶
RequireFileExists asserts that a file exists and optionally checks its content
func RequireFileNotContains ¶
RequireFileNotContains returns a check function that verifies file doesn't contain text
func RequireFilePermissions ¶
RequireFilePermissions asserts that a file has specific permissions
func RequireMigrationCount ¶
RequireMigrationCount asserts that a specific number of migrations exist
func RequireMigrationValid ¶
RequireMigrationValid asserts that a migration file is valid SQL
func RequireNoDir ¶
RequireNoDir asserts that a directory does not exist
func RequireNoError ¶
RequireNoError asserts that no error occurred
func RequireNoFile ¶
RequireNoFile asserts that a file does not exist
func RequireSchemaEqual ¶
RequireSchemaEqual asserts that two SQL schemas are functionally equivalent
func RequireSumFileValid ¶
RequireSumFileValid asserts that a sum file exists and has valid format
func RequireValidProject ¶
RequireValidProject asserts that a project structure is correctly initialized
func RunCommand ¶
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 ¶
SkipIfNoDocker skips the test if Docker is not available
func StartClickHouseContainer ¶
StartClickHouseContainer starts a ClickHouse container and returns it
func TestClickHouseXMLConfig ¶
TestClickHouseXMLConfig returns a test ClickHouse XML configuration
func TestCommandExecution ¶
TestCommandExecution runs a command and verifies it executes without error
func TestCommandExecutionWithError ¶
TestCommandExecutionWithError runs a command and returns the error
func TestHousekeeperYAMLConfig ¶
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
Types ¶
type MigrationFile ¶
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 ¶
func (m *MockClickHouseContainer) GetDSN(ctx context.Context) (string, error)
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
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 ¶
TestConfig represents test configuration options