testutil

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testutil provides test utilities for CBT, including:

  • ClickHouse container helpers for integration tests (clickhouse.go)
  • Redis container helpers for integration tests (redis.go)
  • Miniredis helpers for unit tests (miniredis.go)

Integration test utilities require Docker and are gated behind the "integration" build tag. To run integration tests:

go test -tags=integration ./...

Unit test helpers (miniredis) do not require Docker and work with regular tests.

Index

Constants

This section is empty.

Variables

View Source
var ErrFakeNodeNotFound = errors.New("node not found")

ErrFakeNodeNotFound is the default error returned by FakeDAGReader lookups that miss.

Functions

func NewMiniredisClient

func NewMiniredisClient(t *testing.T) (*miniredis.Miniredis, *redis.Client)

NewMiniredisClient returns both a miniredis server and a connected client. Miniredis provides an in-memory Redis for unit tests (no Docker needed). Both are automatically closed when the test completes.

Types

type FakeClickHouseClient added in v0.1.7

type FakeClickHouseClient struct {
	TableExists bool
	BoundsMin   uint64
	BoundsMax   uint64

	QueryOneErr   error
	QueryManyErr  error
	ExecuteErr    error
	BulkInsertErr error

	// QueryOneFn fully overrides QueryOne when set.
	QueryOneFn func(ctx context.Context, query string, dest any) error
}

FakeClickHouseClient is a configurable fake implementing clickhouse.ClientInterface.

The zero value returns no error from every method and writes nothing into query destinations. QueryOne uses reflection to populate result structs so callers do not depend on ch struct tags:

  • For queries that mention "system.tables" it sets the "Count" field to 1 when TableExists is true, otherwise 0.
  • For all other queries it sets the "Min" and "Max" fields from BoundsMin / BoundsMax.

Inject failures via the *Err fields.

func (*FakeClickHouseClient) BulkInsert added in v0.1.7

func (f *FakeClickHouseClient) BulkInsert(_ context.Context, _ string, _ any) error

BulkInsert returns BulkInsertErr.

func (*FakeClickHouseClient) Execute added in v0.1.7

func (f *FakeClickHouseClient) Execute(_ context.Context, _ string) error

Execute returns ExecuteErr.

func (*FakeClickHouseClient) QueryMany added in v0.1.7

func (f *FakeClickHouseClient) QueryMany(_ context.Context, _ string, _ any) error

QueryMany returns QueryManyErr and writes nothing.

func (*FakeClickHouseClient) QueryOne added in v0.1.7

func (f *FakeClickHouseClient) QueryOne(ctx context.Context, query string, dest any) error

QueryOne populates dest via reflection based on the query shape (see type docs).

func (*FakeClickHouseClient) Start added in v0.1.7

func (f *FakeClickHouseClient) Start() error

Start is a no-op.

func (*FakeClickHouseClient) Stop added in v0.1.7

func (f *FakeClickHouseClient) Stop() error

Stop is a no-op.

type FakeDAGReader added in v0.1.7

type FakeDAGReader struct {
	Transformations []models.Transformation
	Externals       []models.Node

	TransformationByID map[string]models.Transformation
	ExternalByID       map[string]models.External
	NodeByID           map[string]models.Node

	Dependencies    map[string][]string
	Dependents      map[string][]string
	AllDependencies map[string][]string
	AllDependents   map[string][]string
	PathBetween     map[string]map[string]bool

	// NotFoundErr is returned by GetTransformationNode when NodeNotFound is set; defaults
	// to ErrFakeNodeNotFound.
	NodeNotFound bool
	NotFoundErr  error

	// Single external-node conveniences used by the executor tests.
	ExternalNode    models.External
	ExternalNodeErr error

	// Error injection for keyed lookups.
	GetTransformationErr error
	GetExternalErr       error
	GetNodeErr           error

	// TransformationFallbackFn supplies a default node when a slice/map lookup misses and no
	// error is configured. When nil, GetTransformationNode returns a not-found error on a miss.
	TransformationFallbackFn func(id string) models.Transformation
}

FakeDAGReader is a configurable fake implementing models.DAGReader for tests.

The zero value returns empty results from every method. It supports two lookup styles that the hand-rolled copies relied on:

  • Slice style: set Transformations / Externals; GetTransformationNode linear-searches Transformations by ID and, on a miss, calls TransformationFallbackFn (if set) so a default node can be synthesized the way some callers expect.
  • Map style: set TransformationByID / ExternalByID / NodeByID for direct keyed lookups that return ErrFakeNodeNotFound (or the configured *Err) on a miss.

Dependency relationships are read from the Dependencies / Dependents / AllDependencies / AllDependents / PathBetween maps. Inject lookup errors via the *Err fields, or force a miss on GetTransformationNode with NodeNotFound.

func (*FakeDAGReader) GetAllDependencies added in v0.1.7

func (f *FakeDAGReader) GetAllDependencies(id string) []string

GetAllDependencies returns the configured transitive dependencies of id.

func (*FakeDAGReader) GetAllDependents added in v0.1.7

func (f *FakeDAGReader) GetAllDependents(id string) []string

GetAllDependents returns the configured transitive dependents of id.

func (*FakeDAGReader) GetDependencies added in v0.1.7

func (f *FakeDAGReader) GetDependencies(id string) []string

GetDependencies returns the configured direct dependencies of id.

func (*FakeDAGReader) GetDependents added in v0.1.7

func (f *FakeDAGReader) GetDependents(id string) []string

GetDependents returns the configured direct dependents of id.

func (*FakeDAGReader) GetExternalNode added in v0.1.7

func (f *FakeDAGReader) GetExternalNode(id string) (models.External, error)

GetExternalNode returns the external registered under id.

Resolution order: configured GetExternalErr/ExternalNodeErr -> ExternalByID map -> single ExternalNode convenience -> not-found error.

func (*FakeDAGReader) GetExternalNodes added in v0.1.7

func (f *FakeDAGReader) GetExternalNodes() []models.Node

GetExternalNodes returns the configured Externals.

func (*FakeDAGReader) GetNode added in v0.1.7

func (f *FakeDAGReader) GetNode(id string) (models.Node, error)

GetNode returns the node stored under id, or an error/empty node.

func (*FakeDAGReader) GetStructuredDependencies added in v0.1.7

func (f *FakeDAGReader) GetStructuredDependencies(_ string) []transformation.Dependency

GetStructuredDependencies returns nil; structured dependencies are not modeled by the fake.

func (*FakeDAGReader) GetTransformationNode added in v0.1.7

func (f *FakeDAGReader) GetTransformationNode(id string) (models.Transformation, error)

GetTransformationNode returns the transformation registered under id.

Resolution order: configured GetTransformationErr -> NodeNotFound flag -> TransformationByID map -> Transformations slice (linear search) -> a transformation stored in NodeByID[id] -> TransformationFallbackFn -> not-found error.

func (*FakeDAGReader) GetTransformationNodes added in v0.1.7

func (f *FakeDAGReader) GetTransformationNodes() []models.Transformation

GetTransformationNodes returns the configured Transformations.

func (*FakeDAGReader) IsPathBetween added in v0.1.7

func (f *FakeDAGReader) IsPathBetween(from, to string) bool

IsPathBetween reports whether a path between from and to was configured in PathBetween.

type FakeExternal added in v0.1.7

type FakeExternal struct {
	ID     string
	Type   string
	Value  string
	Config external.Config

	// SetDefaultsFn overrides SetDefaults when set.
	SetDefaultsFn func(defaultCluster, defaultDB string)
}

FakeExternal is a configurable fake implementing models.External for tests.

The zero value returns empty/zero values. Config backs both GetConfig (by value) and GetConfigMutable (by pointer). SetDefaults applies the default database when empty.

func (*FakeExternal) GetConfig added in v0.1.7

func (f *FakeExternal) GetConfig() external.Config

GetConfig returns the configured Config by value.

func (*FakeExternal) GetConfigMutable added in v0.1.7

func (f *FakeExternal) GetConfigMutable() *external.Config

GetConfigMutable returns a pointer to the configured Config.

func (*FakeExternal) GetID added in v0.1.7

func (f *FakeExternal) GetID() string

GetID returns the configured ID.

func (*FakeExternal) GetType added in v0.1.7

func (f *FakeExternal) GetType() string

GetType returns the configured Type, defaulting to "sql".

func (*FakeExternal) GetValue added in v0.1.7

func (f *FakeExternal) GetValue() string

GetValue returns the configured Value.

func (*FakeExternal) SetDefaults added in v0.1.7

func (f *FakeExternal) SetDefaults(defaultCluster, defaultDB string)

SetDefaults applies the default database to the config when the database is empty.

type FakeHandler added in v0.1.7

type FakeHandler struct {
	HandlerType   transformation.Type
	HandlerConfig any
	// TrackPosition overrides ShouldTrackPosition. When nil, ShouldTrackPosition returns true.
	TrackPosition *bool

	AdminTable transformation.AdminTable

	// Schedule / fill flags consumed by the scheduler tests.
	ForwardFillEnabled bool
	ForwardSchedule    string
	BackfillEnabled    bool
	BackfillSchedule   string
	Schedule           string

	// Dependency / interval metadata consumed by the models DAG tests.
	Dependencies []string
	IntervalType string

	// Tags consumed by the worker tag-filtering tests (read via GetTags).
	Tags []string

	// TemplateVariables overrides the value returned by GetTemplateVariables.
	TemplateVariables map[string]any
}

FakeHandler is a configurable fake implementing transformation.Handler (plus the common optional sub-interfaces used in tests) for unit tests.

The zero value reports type "incremental", tracks positions, and returns empty/nil from the variable getters. Fields drive the schedule, interval and dependency getters so the same fake can stand in for incremental, scheduled and templated handler scenarios.

func (*FakeHandler) Config added in v0.1.7

func (f *FakeHandler) Config() any

Config returns the configured handler config (may be nil).

func (*FakeHandler) GetAdminTable added in v0.1.7

func (f *FakeHandler) GetAdminTable() transformation.AdminTable

GetAdminTable returns the configured AdminTable.

func (*FakeHandler) GetBackfillSchedule added in v0.1.7

func (f *FakeHandler) GetBackfillSchedule() string

GetBackfillSchedule returns the configured BackfillSchedule.

func (*FakeHandler) GetFlattenedDependencies added in v0.1.7

func (f *FakeHandler) GetFlattenedDependencies() []string

GetFlattenedDependencies returns the configured Dependencies.

func (*FakeHandler) GetForwardSchedule added in v0.1.7

func (f *FakeHandler) GetForwardSchedule() string

GetForwardSchedule returns the configured ForwardSchedule.

func (*FakeHandler) GetIntervalType added in v0.1.7

func (f *FakeHandler) GetIntervalType() string

GetIntervalType returns the configured IntervalType.

func (*FakeHandler) GetSchedule added in v0.1.7

func (f *FakeHandler) GetSchedule() string

GetSchedule returns the configured Schedule.

func (*FakeHandler) GetTags added in v0.1.7

func (f *FakeHandler) GetTags() []string

GetTags returns the configured Tags.

func (*FakeHandler) GetTemplateVariables added in v0.1.7

func (f *FakeHandler) GetTemplateVariables(_ context.Context, _ transformation.TaskInfo) map[string]any

GetTemplateVariables returns the configured TemplateVariables, or an empty map.

func (*FakeHandler) IsBackfillEnabled added in v0.1.7

func (f *FakeHandler) IsBackfillEnabled() bool

IsBackfillEnabled returns the configured BackfillEnabled flag.

func (*FakeHandler) IsForwardFillEnabled added in v0.1.7

func (f *FakeHandler) IsForwardFillEnabled() bool

IsForwardFillEnabled returns the configured ForwardFillEnabled flag.

func (*FakeHandler) RecordCompletion added in v0.1.7

func (f *FakeHandler) RecordCompletion(_ context.Context, _ any, _ string, _ transformation.TaskInfo) error

RecordCompletion is a no-op that always succeeds.

func (*FakeHandler) ShouldTrackPosition added in v0.1.7

func (f *FakeHandler) ShouldTrackPosition() bool

ShouldTrackPosition returns *TrackPosition when set, otherwise true.

func (*FakeHandler) Type added in v0.1.7

func (f *FakeHandler) Type() transformation.Type

Type returns the configured handler type, defaulting to TypeIncremental.

func (*FakeHandler) Validate added in v0.1.7

func (f *FakeHandler) Validate() error

Validate always succeeds.

type FakeModelsService added in v0.1.7

type FakeModelsService struct {
	DAG             models.DAGReader
	Transformations []models.Transformation

	RenderedSQL string
	RenderErr   error
	EnvVars     *[]string

	// RenderExternalFn overrides RenderExternal when set.
	RenderExternalFn func(model models.External, cacheState map[string]any) (string, error)
}

FakeModelsService is a configurable fake implementing models.Service for tests.

The zero value returns an empty DAG and empty render results. Set DAG to control GetDAG; when DAG is nil and Transformations is set, GetDAG returns a FakeDAGReader backed by Transformations. Render results and errors are driven by the matching fields.

func (*FakeModelsService) GetDAG added in v0.1.7

func (f *FakeModelsService) GetDAG() models.DAGReader

GetDAG returns the configured DAG, or a FakeDAGReader backed by Transformations.

func (*FakeModelsService) GetTransformationEnvironmentVariables added in v0.1.7

func (f *FakeModelsService) GetTransformationEnvironmentVariables(_ models.Transformation, _, _ uint64, _ time.Time) (*[]string, error)

GetTransformationEnvironmentVariables returns EnvVars when set, otherwise an empty slice.

func (*FakeModelsService) RenderExternal added in v0.1.7

func (f *FakeModelsService) RenderExternal(model models.External, cacheState map[string]any) (string, error)

RenderExternal returns an empty string by default.

func (*FakeModelsService) RenderTransformation added in v0.1.7

func (f *FakeModelsService) RenderTransformation(_ models.Transformation, _, _ uint64, _ time.Time) (string, error)

RenderTransformation returns RenderedSQL, or RenderErr when set.

func (*FakeModelsService) Start added in v0.1.7

func (f *FakeModelsService) Start() error

Start is a no-op.

func (*FakeModelsService) Stop added in v0.1.7

func (f *FakeModelsService) Stop() error

Stop is a no-op.

type FakeTransformation added in v0.1.7

type FakeTransformation struct {
	ID      string
	Type    string
	Value   string
	Config  transformation.Config
	Handler transformation.Handler
	Tags    []string

	// SetDefaultDatabaseFn overrides SetDefaultDatabase when set.
	SetDefaultDatabaseFn func(defaultDB string)
}

FakeTransformation is a configurable fake implementing models.Transformation for tests.

The zero value returns empty/zero values from every getter. Set Config to control the returned config (GetConfig returns &Config so callers may mutate it); set Handler to control the returned handler. Type defaults to "transformation" when empty.

When Handler is nil but Tags is non-nil, GetHandler synthesizes a FakeHandler carrying those tags so tag-based filtering (which reads handler.GetTags()) sees them.

func (*FakeTransformation) GetConfig added in v0.1.7

func (f *FakeTransformation) GetConfig() *transformation.Config

GetConfig returns a pointer to the configured Config.

func (*FakeTransformation) GetHandler added in v0.1.7

func (f *FakeTransformation) GetHandler() transformation.Handler

GetHandler returns the configured Handler. When Handler is nil but Tags is set, it returns a FakeHandler carrying those tags; otherwise it returns the Handler (may be nil).

func (*FakeTransformation) GetID added in v0.1.7

func (f *FakeTransformation) GetID() string

GetID returns the configured ID.

func (*FakeTransformation) GetType added in v0.1.7

func (f *FakeTransformation) GetType() string

GetType returns the configured Type, defaulting to "transformation".

func (*FakeTransformation) GetValue added in v0.1.7

func (f *FakeTransformation) GetValue() string

GetValue returns the configured Value.

func (*FakeTransformation) SetDefaultDatabase added in v0.1.7

func (f *FakeTransformation) SetDefaultDatabase(defaultDB string)

SetDefaultDatabase applies defaultDB to the config when the database is empty.

Directories

Path Synopsis
Package adminfake provides a configurable fake admin.Service for tests.
Package adminfake provides a configurable fake admin.Service for tests.
Package coordinatorfake provides a configurable fake coordinator.Service for tests.
Package coordinatorfake provides a configurable fake coordinator.Service for tests.

Jump to

Keyboard shortcuts

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