clickhouse

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package clickhouse provides test mocks for the ClickHouse client. This file should only be imported in test files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientInterface added in v0.1.1

type ClientInterface interface {
	// QueryOne executes a query and returns a single result
	QueryOne(ctx context.Context, query string, dest interface{}) error
	// QueryMany executes a query and returns multiple results
	QueryMany(ctx context.Context, query string, dest interface{}) error
	// Execute runs a query without expecting results
	Execute(ctx context.Context, query string) error
	// BulkInsert performs a bulk insert operation
	BulkInsert(ctx context.Context, table string, data interface{}) error
	// IsStorageEmpty checks if a table has any records matching the given conditions
	IsStorageEmpty(ctx context.Context, table string, conditions map[string]interface{}) (bool, error)
	// SetNetwork updates the network name for metrics labeling
	SetNetwork(network string)
	// Start initializes the client
	Start() error
	// Stop closes the client
	Stop() error
}

ClientInterface defines the methods for interacting with ClickHouse.

func New added in v0.1.1

func New(cfg *Config) (ClientInterface, error)

New creates a new HTTP-based ClickHouse client.

type Config

type Config struct {
	URL           string        `yaml:"url"`
	QueryTimeout  time.Duration `yaml:"query_timeout"`
	InsertTimeout time.Duration `yaml:"insert_timeout"`
	Network       string        `yaml:"network"`
	Processor     string        `yaml:"processor"`
	Debug         bool          `yaml:"debug"`
	KeepAlive     time.Duration `yaml:"keep_alive"`
}

func (*Config) SetDefaults added in v0.1.1

func (c *Config) SetDefaults()

func (*Config) Validate

func (c *Config) Validate() error

type MockCall added in v0.1.1

type MockCall struct {
	Method string
	Args   []interface{}
}

MockCall represents a method call made to the mock.

type MockClient added in v0.1.1

type MockClient struct {
	// Function fields that can be set by tests
	QueryOneFunc   func(ctx context.Context, query string, dest interface{}) error
	QueryManyFunc  func(ctx context.Context, query string, dest interface{}) error
	ExecuteFunc    func(ctx context.Context, query string) error
	BulkInsertFunc func(ctx context.Context, table string, data interface{}) error
	StartFunc      func() error
	StopFunc       func() error

	// Track calls for assertions
	Calls []MockCall
}

MockClient is a mock implementation of ClientInterface for testing. It should only be used in test files, not in production code.

func NewMockClient added in v0.1.1

func NewMockClient() *MockClient

NewMockClient creates a new mock client with default implementations.

func (*MockClient) BulkInsert added in v0.1.1

func (m *MockClient) BulkInsert(ctx context.Context, table string, data interface{}) error

BulkInsert implements ClientInterface.

func (*MockClient) Execute added in v0.1.1

func (m *MockClient) Execute(ctx context.Context, query string) error

Execute implements ClientInterface.

func (*MockClient) GetCallCount added in v0.1.1

func (m *MockClient) GetCallCount(method string) int

GetCallCount returns the number of times a method was called.

func (*MockClient) QueryMany added in v0.1.1

func (m *MockClient) QueryMany(ctx context.Context, query string, dest interface{}) error

QueryMany implements ClientInterface.

func (*MockClient) QueryOne added in v0.1.1

func (m *MockClient) QueryOne(ctx context.Context, query string, dest interface{}) error

QueryOne implements ClientInterface.

func (*MockClient) Reset added in v0.1.1

func (m *MockClient) Reset()

Reset clears all recorded calls.

func (*MockClient) SetError added in v0.1.1

func (m *MockClient) SetError(err error)

SetError sets all functions to return the specified error.

func (*MockClient) SetQueryManyResponse added in v0.1.1

func (m *MockClient) SetQueryManyResponse(data interface{})

SetQueryManyResponse sets up the mock to return specific data for QueryMany.

func (*MockClient) SetQueryOneResponse added in v0.1.1

func (m *MockClient) SetQueryOneResponse(data interface{})

SetQueryOneResponse sets up the mock to return specific data for QueryOne.

func (*MockClient) Start added in v0.1.1

func (m *MockClient) Start() error

Start implements ClientInterface.

func (*MockClient) Stop added in v0.1.1

func (m *MockClient) Stop() error

Stop implements ClientInterface.

func (*MockClient) WasCalled added in v0.1.1

func (m *MockClient) WasCalled(method string) bool

WasCalled returns true if the specified method was called.

Jump to

Keyboard shortcuts

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