Documentation
¶
Overview ¶
Package adminfake provides a configurable fake admin.Service for tests.
It lives in its own package (rather than internal/testutil) because it imports pkg/admin; keeping it separate avoids an import cycle for pkg/admin's own in-package tests, which depend on the base testutil helpers (miniredis, containers).
Index ¶
- type FakeAdminService
- func (f *FakeAdminService) AcquireBoundsLock(ctx context.Context, modelID string) (admin.BoundsLock, error)
- func (f *FakeAdminService) ConsolidateHistoricalData(ctx context.Context, modelID string) (uint64, error)
- func (f *FakeAdminService) DeleteAllConfigOverrides(ctx context.Context) error
- func (f *FakeAdminService) DeleteConfigOverride(ctx context.Context, modelID string) error
- func (f *FakeAdminService) DeleteExternalBounds(ctx context.Context, modelID string) error
- func (f *FakeAdminService) DeletePeriod(ctx context.Context, modelID string, startPos, endPos uint64) (uint64, error)
- func (f *FakeAdminService) FindGaps(ctx context.Context, modelID string, minPos, maxPos, interval uint64) ([]admin.GapInfo, error)
- func (f *FakeAdminService) GetAllConfigOverrides(ctx context.Context) ([]admin.ConfigOverride, error)
- func (f *FakeAdminService) GetAllLastScheduledExecutions(ctx context.Context, modelIDs []string) (map[string]*time.Time, error)
- func (f *FakeAdminService) GetAllProcessedRanges(ctx context.Context, modelIDs []string) (map[string][]admin.ProcessedRange, error)
- func (f *FakeAdminService) GetConfigOverride(ctx context.Context, modelID string) (*admin.ConfigOverride, error)
- func (f *FakeAdminService) GetConfigOverrideVersion(ctx context.Context) (int64, error)
- func (f *FakeAdminService) GetCoverage(ctx context.Context, modelID string, startPos, endPos uint64) (bool, error)
- func (f *FakeAdminService) GetExternalBounds(ctx context.Context, modelID string) (*admin.BoundsCache, error)
- func (f *FakeAdminService) GetFirstPosition(ctx context.Context, modelID string) (uint64, error)
- func (f *FakeAdminService) GetIncrementalAdminDatabase() string
- func (f *FakeAdminService) GetIncrementalAdminTable() string
- func (f *FakeAdminService) GetLastProcessedPosition(ctx context.Context, modelID string) (uint64, error)
- func (f *FakeAdminService) GetLastScheduledExecution(ctx context.Context, modelID string) (*time.Time, error)
- func (f *FakeAdminService) GetNextUnprocessedPosition(ctx context.Context, modelID string) (uint64, error)
- func (f *FakeAdminService) GetProcessedRanges(ctx context.Context, modelID string) ([]admin.ProcessedRange, error)
- func (f *FakeAdminService) GetScheduledAdminDatabase() string
- func (f *FakeAdminService) GetScheduledAdminTable() string
- func (f *FakeAdminService) RecordCompletion(ctx context.Context, modelID string, position, interval uint64) error
- func (f *FakeAdminService) RecordScheduledCompletion(ctx context.Context, modelID string, startDateTime time.Time) error
- func (f *FakeAdminService) SetConfigOverride(ctx context.Context, override *admin.ConfigOverride) error
- func (f *FakeAdminService) SetExternalBounds(ctx context.Context, cache *admin.BoundsCache) error
- type FakeBoundsLock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FakeAdminService ¶
type FakeAdminService struct {
// Stateful conveniences. Nil maps are treated as empty (lazily allocated on write).
LastPositions map[string]uint64
FirstPositions map[string]uint64
Gaps map[string][]admin.GapInfo
ExternalBounds map[string]*admin.BoundsCache
// ExternalBoundsDefault is returned by GetExternalBounds for any modelID not present in
// the ExternalBounds map. It mirrors the single-value bounds mocks used by the executor
// tests where the same cache is returned regardless of the requested model.
ExternalBoundsDefault *admin.BoundsCache
// ConfigOverrides backs GetAllConfigOverrides; ConfigOverrideByID backs GetConfigOverride.
ConfigOverrides []admin.ConfigOverride
ConfigOverrideByID map[string]*admin.ConfigOverride
// Admin table identifiers returned by the GetXxxAdmin* getters. Empty strings fall
// back to sensible defaults to match the most common hand-rolled copies.
IncrementalDatabase string
IncrementalTable string
ScheduledDatabase string
ScheduledTable string
// Optional callback invoked by SetExternalBounds before storing, useful for
// capturing the saved cache in assertions.
OnSetExternalBounds func(*admin.BoundsCache)
// Function-field overrides. When set they take precedence over the default behavior.
GetNextUnprocessedPositionFn func(ctx context.Context, modelID string) (uint64, error)
GetLastProcessedPositionFn func(ctx context.Context, modelID string) (uint64, error)
GetFirstPositionFn func(ctx context.Context, modelID string) (uint64, error)
RecordCompletionFn func(ctx context.Context, modelID string, position, interval uint64) error
RecordScheduledCompletionFn func(ctx context.Context, modelID string, startDateTime time.Time) error
GetLastScheduledExecutionFn func(ctx context.Context, modelID string) (*time.Time, error)
GetAllLastScheduledExecutionsFn func(ctx context.Context, modelIDs []string) (map[string]*time.Time, error)
GetCoverageFn func(ctx context.Context, modelID string, startPos, endPos uint64) (bool, error)
GetProcessedRangesFn func(ctx context.Context, modelID string) ([]admin.ProcessedRange, error)
GetAllProcessedRangesFn func(ctx context.Context, modelIDs []string) (map[string][]admin.ProcessedRange, error)
FindGapsFn func(ctx context.Context, modelID string, minPos, maxPos, interval uint64) ([]admin.GapInfo, error)
ConsolidateHistoricalDataFn func(ctx context.Context, modelID string) (uint64, error)
DeletePeriodFn func(ctx context.Context, modelID string, startPos, endPos uint64) (uint64, error)
GetExternalBoundsFn func(ctx context.Context, modelID string) (*admin.BoundsCache, error)
SetExternalBoundsFn func(ctx context.Context, cache *admin.BoundsCache) error
DeleteExternalBoundsFn func(ctx context.Context, modelID string) error
AcquireBoundsLockFn func(ctx context.Context, modelID string) (admin.BoundsLock, error)
GetConfigOverrideFn func(ctx context.Context, modelID string) (*admin.ConfigOverride, error)
GetAllConfigOverridesFn func(ctx context.Context) ([]admin.ConfigOverride, error)
SetConfigOverrideFn func(ctx context.Context, override *admin.ConfigOverride) error
DeleteConfigOverrideFn func(ctx context.Context, modelID string) error
DeleteAllConfigOverridesFn func(ctx context.Context) error
GetConfigOverrideVersionFn func(ctx context.Context) (int64, error)
// contains filtered or unexported fields
}
FakeAdminService is a configurable in-memory fake implementing admin.Service for unit tests.
The zero value behaves like the most common hand-rolled copy: every method returns zero values and no error. Override individual methods via the *Fn function fields, or rely on the built-in stateful conveniences:
- LastPositions / FirstPositions / Gaps / ExternalBounds maps back the position, gap and bounds getters.
- RecordCompletion records the latest position into LastPositions.
- SetExternalBounds stores into ExternalBounds keyed by cache.ModelID.
- ConfigOverrides / ConfigOverrideByID back the config-override getters.
All map access is guarded by an internal mutex so the fake is race-safe.
func (*FakeAdminService) AcquireBoundsLock ¶
func (f *FakeAdminService) AcquireBoundsLock(ctx context.Context, modelID string) (admin.BoundsLock, error)
AcquireBoundsLock returns a no-op FakeBoundsLock by default.
func (*FakeAdminService) ConsolidateHistoricalData ¶
func (f *FakeAdminService) ConsolidateHistoricalData(ctx context.Context, modelID string) (uint64, error)
ConsolidateHistoricalData returns 0 by default.
func (*FakeAdminService) DeleteAllConfigOverrides ¶
func (f *FakeAdminService) DeleteAllConfigOverrides(ctx context.Context) error
DeleteAllConfigOverrides is a no-op by default.
func (*FakeAdminService) DeleteConfigOverride ¶
func (f *FakeAdminService) DeleteConfigOverride(ctx context.Context, modelID string) error
DeleteConfigOverride is a no-op by default.
func (*FakeAdminService) DeleteExternalBounds ¶
func (f *FakeAdminService) DeleteExternalBounds(ctx context.Context, modelID string) error
DeleteExternalBounds removes the stored bounds for modelID.
func (*FakeAdminService) DeletePeriod ¶
func (f *FakeAdminService) DeletePeriod(ctx context.Context, modelID string, startPos, endPos uint64) (uint64, error)
DeletePeriod returns 0 by default.
func (*FakeAdminService) FindGaps ¶
func (f *FakeAdminService) FindGaps(ctx context.Context, modelID string, minPos, maxPos, interval uint64) ([]admin.GapInfo, error)
FindGaps returns the recorded gaps for modelID, or an empty slice.
func (*FakeAdminService) GetAllConfigOverrides ¶
func (f *FakeAdminService) GetAllConfigOverrides(ctx context.Context) ([]admin.ConfigOverride, error)
GetAllConfigOverrides returns ConfigOverrides.
func (*FakeAdminService) GetAllLastScheduledExecutions ¶
func (f *FakeAdminService) GetAllLastScheduledExecutions(ctx context.Context, modelIDs []string) (map[string]*time.Time, error)
GetAllLastScheduledExecutions returns an empty map by default.
func (*FakeAdminService) GetAllProcessedRanges ¶
func (f *FakeAdminService) GetAllProcessedRanges(ctx context.Context, modelIDs []string) (map[string][]admin.ProcessedRange, error)
GetAllProcessedRanges returns an empty map by default.
func (*FakeAdminService) GetConfigOverride ¶
func (f *FakeAdminService) GetConfigOverride(ctx context.Context, modelID string) (*admin.ConfigOverride, error)
GetConfigOverride returns the override stored under modelID, or nil.
func (*FakeAdminService) GetConfigOverrideVersion ¶
func (f *FakeAdminService) GetConfigOverrideVersion(ctx context.Context) (int64, error)
GetConfigOverrideVersion returns 0 by default.
func (*FakeAdminService) GetCoverage ¶
func (f *FakeAdminService) GetCoverage(ctx context.Context, modelID string, startPos, endPos uint64) (bool, error)
GetCoverage returns false by default.
func (*FakeAdminService) GetExternalBounds ¶
func (f *FakeAdminService) GetExternalBounds(ctx context.Context, modelID string) (*admin.BoundsCache, error)
GetExternalBounds returns the stored bounds for modelID, or nil.
func (*FakeAdminService) GetFirstPosition ¶
GetFirstPosition returns the recorded first position for modelID, or 0.
func (*FakeAdminService) GetIncrementalAdminDatabase ¶
func (f *FakeAdminService) GetIncrementalAdminDatabase() string
GetIncrementalAdminDatabase returns IncrementalDatabase, defaulting to "admin".
func (*FakeAdminService) GetIncrementalAdminTable ¶
func (f *FakeAdminService) GetIncrementalAdminTable() string
GetIncrementalAdminTable returns IncrementalTable, defaulting to "cbt_incremental".
func (*FakeAdminService) GetLastProcessedPosition ¶
func (f *FakeAdminService) GetLastProcessedPosition(ctx context.Context, modelID string) (uint64, error)
GetLastProcessedPosition returns the recorded position for modelID, or 0.
func (*FakeAdminService) GetLastScheduledExecution ¶
func (f *FakeAdminService) GetLastScheduledExecution(ctx context.Context, modelID string) (*time.Time, error)
GetLastScheduledExecution returns nil by default.
func (*FakeAdminService) GetNextUnprocessedPosition ¶
func (f *FakeAdminService) GetNextUnprocessedPosition(ctx context.Context, modelID string) (uint64, error)
GetNextUnprocessedPosition returns the recorded position for modelID, or 0.
func (*FakeAdminService) GetProcessedRanges ¶
func (f *FakeAdminService) GetProcessedRanges(ctx context.Context, modelID string) ([]admin.ProcessedRange, error)
GetProcessedRanges returns an empty slice by default.
func (*FakeAdminService) GetScheduledAdminDatabase ¶
func (f *FakeAdminService) GetScheduledAdminDatabase() string
GetScheduledAdminDatabase returns ScheduledDatabase, defaulting to "admin".
func (*FakeAdminService) GetScheduledAdminTable ¶
func (f *FakeAdminService) GetScheduledAdminTable() string
GetScheduledAdminTable returns ScheduledTable, defaulting to "cbt_scheduled".
func (*FakeAdminService) RecordCompletion ¶
func (f *FakeAdminService) RecordCompletion(ctx context.Context, modelID string, position, interval uint64) error
RecordCompletion records position into LastPositions for modelID.
func (*FakeAdminService) RecordScheduledCompletion ¶
func (f *FakeAdminService) RecordScheduledCompletion(ctx context.Context, modelID string, startDateTime time.Time) error
RecordScheduledCompletion records a completed scheduled transformation (no-op by default).
func (*FakeAdminService) SetConfigOverride ¶
func (f *FakeAdminService) SetConfigOverride(ctx context.Context, override *admin.ConfigOverride) error
SetConfigOverride is a no-op by default.
func (*FakeAdminService) SetExternalBounds ¶
func (f *FakeAdminService) SetExternalBounds(ctx context.Context, cache *admin.BoundsCache) error
SetExternalBounds stores cache keyed by cache.ModelID.
type FakeBoundsLock ¶
type FakeBoundsLock struct{}
FakeBoundsLock is a no-op implementation of admin.BoundsLock for tests.