Documentation
¶
Index ¶
- type MockRegistry
- func (r *MockRegistry) AddPassthroughs(passthroughs []string)
- func (r *MockRegistry) AddVerifyErrors(errors []string)
- func (r *MockRegistry) CheckNegativeGRPCMocks(service, method string)
- func (r *MockRegistry) CheckNegativeHTTPMocks(url string, method string)
- func (r *MockRegistry) CheckNegativeMocks(key string, query string)
- func (r *MockRegistry) CheckNegativeMocksByTables(tables []string, operation string, whereColumns []string, ...)
- func (r *MockRegistry) CheckNegativeRedisMocks(command, key string)
- func (r *MockRegistry) ClearState()
- func (r *MockRegistry) FindGRPCMock(service, method string) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindGRPCMockWithBody(service, method string, bodyMatch func(withFile, baseDir string) bool) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindHTTPMock(url string, method string) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindHTTPMockWithBody(url, method string, headers map[string]string, ...) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindKafkaMockWithBody(topic string, bodyMatch func(withFile, baseDir string) bool) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindMock(key string, query string) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindMockByTables(tables []string, operation string, whereColumns []string, ...) (*types.ExpectStatement, bool)
- func (r *MockRegistry) FindRedisMock(command, key string) (*types.ExpectStatement, bool)
- func (r *MockRegistry) GetEventTopics() []string
- func (r *MockRegistry) GetHits() map[string]int
- func (r *MockRegistry) GetPassthroughs() []string
- func (r *MockRegistry) GetSeeds() map[string][][]byte
- func (r *MockRegistry) GetTables() []string
- func (r *MockRegistry) GetVariables() map[string]string
- func (r *MockRegistry) GetVerifyErrors() []string
- func (r *MockRegistry) LoadFromBytes(data []byte) error
- func (r *MockRegistry) LoadFromFile(path string) error
- func (r *MockRegistry) PeekMock(key string, query string) (*types.ExpectStatement, bool)
- func (r *MockRegistry) PeekMockByTables(tables []string, operation string, whereColumns []string, ...) (*types.ExpectStatement, bool)
- func (r *MockRegistry) PopRedisSeed(key string) []byte
- func (r *MockRegistry) RecordPassthrough(description string)
- func (r *MockRegistry) RecordVerifyError(msg string)
- func (r *MockRegistry) Register(spec *types.TestSpec)
- func (r *MockRegistry) ResetHits()
- func (r *MockRegistry) SaveToFile(path string) error
- func (r *MockRegistry) SaveToFileForContainer(path, hostCwd, containerProjectMount string) error
- func (r *MockRegistry) SeedRedisQueue(key string, value []byte)
- func (r *MockRegistry) SeedTopic(topic string, value []byte)
- func (r *MockRegistry) SetHits(hostHits map[string]int)
- func (r *MockRegistry) SetVarTypes(types map[string]string)
- func (r *MockRegistry) SetVariables(vars map[string]string)
- func (r *MockRegistry) ToBytesForContainer(hostCwd, containerProjectMount string) ([]byte, error)
- func (r *MockRegistry) VerifyAll() error
- func (r *MockRegistry) VerifyPassthroughs(strict bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockRegistry ¶
func NewMockRegistry ¶
func NewMockRegistry() *MockRegistry
func (*MockRegistry) AddPassthroughs ¶
func (r *MockRegistry) AddPassthroughs(passthroughs []string)
AddPassthroughs merges passthrough records from a proxy container into this registry.
func (*MockRegistry) AddVerifyErrors ¶
func (r *MockRegistry) AddVerifyErrors(errors []string)
AddVerifyErrors merges VERIFY failure records from a proxy container into this registry.
func (*MockRegistry) CheckNegativeGRPCMocks ¶
func (r *MockRegistry) CheckNegativeGRPCMocks(service, method string)
CheckNegativeGRPCMocks checks incoming gRPC requests against negative expectations.
func (*MockRegistry) CheckNegativeHTTPMocks ¶
func (r *MockRegistry) CheckNegativeHTTPMocks(url string, method string)
CheckNegativeHTTPMocks checks incoming HTTP requests against negative expectations and increments their hit counters if matched. Called by the HTTP proxy alongside FindHTTPMock so that EXPECT_NOT violations are detected at verification time.
func (*MockRegistry) CheckNegativeMocks ¶
func (r *MockRegistry) CheckNegativeMocks(key string, query string)
CheckNegativeMocks checks incoming DB/Kafka requests against negative expectations and increments their hit counters if matched. Called by proxies alongside FindMock so that EXPECT_NOT violations are detected at verification time.
func (*MockRegistry) CheckNegativeMocksByTables ¶
func (r *MockRegistry) CheckNegativeMocksByTables( tables []string, operation string, whereColumns []string, whereValues map[string]string, writtenValues map[string]string, )
CheckNegativeMocksByTables checks semantic negative expectations against an incoming query.
func (*MockRegistry) CheckNegativeRedisMocks ¶
func (r *MockRegistry) CheckNegativeRedisMocks(command, key string)
CheckNegativeRedisMocks checks incoming Redis commands against negative expectations.
func (*MockRegistry) ClearState ¶
func (r *MockRegistry) ClearState()
ClearState resets hits, passthroughs, and verifyErrors without touching mocks. Used after LoadFromBytes/LoadFromFile when hot-reloading between test runs.
func (*MockRegistry) FindGRPCMock ¶
func (r *MockRegistry) FindGRPCMock(service, method string) (*types.ExpectStatement, bool)
FindGRPCMock finds a gRPC mock matching the service and method.
func (*MockRegistry) FindGRPCMockWithBody ¶
func (r *MockRegistry) FindGRPCMockWithBody(service, method string, bodyMatch func(withFile, baseDir string) bool) (*types.ExpectStatement, bool)
FindGRPCMockWithBody finds a gRPC mock matching the service and method, also filtering by the request body when the mock declares a WithFile. bodyMatch follows the same contract as in FindHTTPMockWithBody.
func (*MockRegistry) FindHTTPMock ¶
func (r *MockRegistry) FindHTTPMock(url string, method string) (*types.ExpectStatement, bool)
FindHTTPMock finds an HTTP mock matching both URL and method
func (*MockRegistry) FindHTTPMockWithBody ¶
func (r *MockRegistry) FindHTTPMockWithBody(url, method string, headers map[string]string, bodyMatch func(withFile, baseDir string) bool) (*types.ExpectStatement, bool)
FindHTTPMockWithBody finds an HTTP mock matching URL, method, headers, and optionally the request body. bodyMatch is called for each candidate; it receives the mock's WithFile path and BaseDir and returns true if the body matches (or if no body constraint should be applied). Mocks with an empty WithFile always satisfy the check.
func (*MockRegistry) FindKafkaMockWithBody ¶
func (r *MockRegistry) FindKafkaMockWithBody(topic string, bodyMatch func(withFile, baseDir string) bool) (*types.ExpectStatement, bool)
FindKafkaMockWithBody finds a Kafka mock for the given topic, also filtering by the message body when the mock declares a WithFile. bodyMatch follows the same contract as in FindHTTPMockWithBody.
func (*MockRegistry) FindMock ¶
func (r *MockRegistry) FindMock(key string, query string) (*types.ExpectStatement, bool)
func (*MockRegistry) FindMockByTables ¶
func (r *MockRegistry) FindMockByTables( tables []string, operation string, whereColumns []string, whereValues map[string]string, writtenValues map[string]string, ) (*types.ExpectStatement, bool)
FindMockByTables finds the best-matching mock for a SQL query using the semantic matching system (ACCESSING_TABLES + VERIFY_ clauses). Returns nil, false if no semantic mock matches; callers should then fall back to FindMock for legacy mocks.
Matching algorithm:
- Candidate set: mocks where AccessingTables exactly equals tables (sorted) and 0 hits
- Filter: all declared VERIFY_ constraints must pass (AND logic)
- Score by specificity (number of declared VERIFY_ clauses)
- Tiebreak: prefer CALL N ordering (lowest N with 0 hits); then declaration order
func (*MockRegistry) FindRedisMock ¶
func (r *MockRegistry) FindRedisMock(command, key string) (*types.ExpectStatement, bool)
FindRedisMock finds a Redis mock matching the command and key.
func (*MockRegistry) GetEventTopics ¶
func (r *MockRegistry) GetEventTopics() []string
GetEventTopics returns all distinct Kafka topic names from EVENT channel mocks.
func (*MockRegistry) GetHits ¶
func (r *MockRegistry) GetHits() map[string]int
func (*MockRegistry) GetPassthroughs ¶
func (r *MockRegistry) GetPassthroughs() []string
GetPassthroughs returns a copy of all recorded passthrough descriptions.
func (*MockRegistry) GetSeeds ¶
func (r *MockRegistry) GetSeeds() map[string][][]byte
GetSeeds returns a copy of all seeded Kafka messages.
func (*MockRegistry) GetTables ¶
func (r *MockRegistry) GetTables() []string
GetTables returns a list of unique table names registered in the registry. For semantic mocks (ACCESSING_TABLES), each individual table name is returned so that proxy table-detection logic can match them.
func (*MockRegistry) GetVariables ¶
func (r *MockRegistry) GetVariables() map[string]string
GetVariables returns a copy of the resolved interpolation variables.
func (*MockRegistry) GetVerifyErrors ¶
func (r *MockRegistry) GetVerifyErrors() []string
GetVerifyErrors returns a copy of all recorded VERIFY failures.
func (*MockRegistry) LoadFromBytes ¶
func (r *MockRegistry) LoadFromBytes(data []byte) error
LoadFromBytes replaces the registry contents from JSON bytes (same format as SaveToFile).
func (*MockRegistry) LoadFromFile ¶
func (r *MockRegistry) LoadFromFile(path string) error
func (*MockRegistry) PeekMock ¶
func (r *MockRegistry) PeekMock(key string, query string) (*types.ExpectStatement, bool)
PeekMock checks if a mock exists without incrementing hit count (used for testing intercept)
func (*MockRegistry) PeekMockByTables ¶
func (r *MockRegistry) PeekMockByTables( tables []string, operation string, whereColumns []string, whereValues map[string]string, writtenValues map[string]string, ) (*types.ExpectStatement, bool)
PeekMockByTables is like FindMockByTables but does not increment hit counts.
func (*MockRegistry) PopRedisSeed ¶
func (r *MockRegistry) PopRedisSeed(key string) []byte
PopRedisSeed atomically removes and returns the first seeded payload for key, or nil. This is the canonical way for proxy interceptors to consume seeds so they stay in sync with the registry even after a hot-reload via /reload-registry.
func (*MockRegistry) RecordPassthrough ¶
func (r *MockRegistry) RecordPassthrough(description string)
RecordPassthrough records that a request bypassed the mock layer (no matching mock found). description should be a short human-readable string identifying the request, e.g. "SELECT users".
func (*MockRegistry) RecordVerifyError ¶
func (r *MockRegistry) RecordVerifyError(msg string)
RecordVerifyError records a VERIFY rule failure. Called by proxies when a VERIFY check fails.
func (*MockRegistry) Register ¶
func (r *MockRegistry) Register(spec *types.TestSpec)
func (*MockRegistry) ResetHits ¶
func (r *MockRegistry) ResetHits()
ResetHits resets the hit count for all mocks (useful for testing)
func (*MockRegistry) SaveToFile ¶
func (r *MockRegistry) SaveToFile(path string) error
func (*MockRegistry) SaveToFileForContainer ¶
func (r *MockRegistry) SaveToFileForContainer(path, hostCwd, containerProjectMount string) error
SaveToFileForContainer saves the registry to path with BaseDir fields rewritten for use inside a Docker container. See ToBytesForContainer for parameter docs.
func (*MockRegistry) SeedRedisQueue ¶
func (r *MockRegistry) SeedRedisQueue(key string, value []byte)
SeedRedisQueue adds a raw payload to be served to Redis workers on a given queue key. The seed is returned on the worker's next BRPOP/BLPOP/LPOP call for that key.
func (*MockRegistry) SeedTopic ¶
func (r *MockRegistry) SeedTopic(topic string, value []byte)
SeedTopic adds a raw payload to be served to Kafka consumers on a given topic.
func (*MockRegistry) SetHits ¶
func (r *MockRegistry) SetHits(hostHits map[string]int)
func (*MockRegistry) SetVarTypes ¶
func (r *MockRegistry) SetVarTypes(types map[string]string)
SetVarTypes stores declared variable types so they are included when the registry is serialised for proxy containers.
func (*MockRegistry) SetVariables ¶
func (r *MockRegistry) SetVariables(vars map[string]string)
SetVariables stores resolved interpolation variables so they are included when the registry is serialised for proxy containers.
func (*MockRegistry) ToBytesForContainer ¶
func (r *MockRegistry) ToBytesForContainer(hostCwd, containerProjectMount string) ([]byte, error)
ToBytesForContainer serialises the registry with all BaseDir fields rewritten from absolute host paths to container-internal paths. hostCwd is the host working directory; containerProjectMount is where it is bind-mounted inside the proxy sidecar container (e.g. "/app/project").
func (*MockRegistry) VerifyAll ¶
func (r *MockRegistry) VerifyAll() error
func (*MockRegistry) VerifyPassthroughs ¶
func (r *MockRegistry) VerifyPassthroughs(strict bool) error
VerifyPassthroughs logs a warning for every recorded passthrough. If strict is true and any passthroughs were recorded, it returns an error so the test fails.