Documentation
¶
Overview ¶
Package mocks provides mock implementations for testing.
This package contains:
- Interface definitions for mockable dependencies
- Mock implementations for gRPC clients
- Mock implementations for database operations
- Test helpers and fixtures
Usage:
func TestSomething(t *testing.T) {
mock := mocks.NewMockFunctionStore()
mock.SetReturnValue("function1", expectedResult)
// use mock in test
}
Index ¶
- type FunctionInfo
- type InvokeRequest
- type InvokeResponse
- type JobEvent
- type MockConfig
- type MockFunctionStore
- type MockGRPCClient
- func (m *MockGRPCClient) CancelJob(ctx context.Context, jobID string) error
- func (m *MockGRPCClient) ClearCalls()
- func (m *MockGRPCClient) GetCalls() []string
- func (m *MockGRPCClient) Invoke(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error)
- func (m *MockGRPCClient) SetError(err error)
- func (m *MockGRPCClient) SetInvokeFunc(f func(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error))
- func (m *MockGRPCClient) SetStartJobFunc(f func(ctx context.Context, req *InvokeRequest) (string, error))
- func (m *MockGRPCClient) SetStreamEvents(events []*JobEvent)
- func (m *MockGRPCClient) StartJob(ctx context.Context, req *InvokeRequest) (string, error)
- func (m *MockGRPCClient) StreamJob(ctx context.Context, jobID string) ([]*JobEvent, error)
- type MockServiceContext
- func (m *MockServiceContext) AddFunction(id string, handler interface{})
- func (m *MockServiceContext) FunctionCount() int
- func (m *MockServiceContext) GetActiveJobs() int
- func (m *MockServiceContext) GetFunctions() map[string]interface{}
- func (m *MockServiceContext) GetLastHeartbeat() time.Time
- func (m *MockServiceContext) GetRegisteredAt() time.Time
- func (m *MockServiceContext) IsRunning() bool
- func (m *MockServiceContext) SetActiveJobs(count int)
- func (m *MockServiceContext) SetConfig(config *MockConfig)
- func (m *MockServiceContext) SetLastHeartbeat(t time.Time)
- func (m *MockServiceContext) SetRegisteredAt(t time.Time)
- func (m *MockServiceContext) SetRunning(running bool)
- func (m *MockServiceContext) SetStartTime(t time.Time)
- func (m *MockServiceContext) Uptime() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FunctionInfo ¶
type FunctionInfo struct {
FunctionID string
DisplayName string
Tags []string
InputSchema string
OutputSchema string
}
FunctionInfo represents a registered function's metadata.
type InvokeRequest ¶
InvokeRequest represents a function invocation request.
type InvokeResponse ¶
InvokeResponse represents a function invocation response.
type JobEvent ¶
type JobEvent struct {
JobID string
EventType string // "progress", "log", "done", "error"
Data []byte
}
JobEvent represents a job execution event.
type MockConfig ¶
type MockConfig struct {
AgentID string
GameID string
Env string
LocalAddr string
ServerAddr string
HeartbeatInterval int64
}
MockConfig holds mock configuration values.
func DefaultMockConfig ¶
func DefaultMockConfig() *MockConfig
DefaultMockConfig returns a default mock configuration.
type MockFunctionStore ¶
type MockFunctionStore struct {
// contains filtered or unexported fields
}
MockFunctionStore is a mock implementation of function storage for testing.
func NewMockFunctionStore ¶
func NewMockFunctionStore() *MockFunctionStore
NewMockFunctionStore creates a new mock function store.
func (*MockFunctionStore) AddFunction ¶
func (m *MockFunctionStore) AddFunction(info *FunctionInfo)
AddFunction adds a function to the mock store.
func (*MockFunctionStore) Clear ¶
func (m *MockFunctionStore) Clear()
Clear removes all functions from the mock store.
func (*MockFunctionStore) GetFunction ¶
func (m *MockFunctionStore) GetFunction(functionID string) (*FunctionInfo, error)
GetFunction retrieves a function from the mock store.
func (*MockFunctionStore) ListFunctions ¶
func (m *MockFunctionStore) ListFunctions() ([]*FunctionInfo, error)
ListFunctions returns all functions in the mock store.
func (*MockFunctionStore) SetError ¶
func (m *MockFunctionStore) SetError(err error)
SetError configures the mock to return an error.
type MockGRPCClient ¶
type MockGRPCClient struct {
// contains filtered or unexported fields
}
MockGRPCClient is a mock implementation of gRPC client for testing.
func NewMockGRPCClient ¶
func NewMockGRPCClient() *MockGRPCClient
NewMockGRPCClient creates a new mock gRPC client.
func (*MockGRPCClient) CancelJob ¶
func (m *MockGRPCClient) CancelJob(ctx context.Context, jobID string) error
CancelJob cancels a mock job.
func (*MockGRPCClient) ClearCalls ¶
func (m *MockGRPCClient) ClearCalls()
ClearCalls clears all recorded calls.
func (*MockGRPCClient) GetCalls ¶
func (m *MockGRPCClient) GetCalls() []string
GetCalls returns all recorded calls.
func (*MockGRPCClient) Invoke ¶
func (m *MockGRPCClient) Invoke(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error)
Invoke performs a mock function invocation.
func (*MockGRPCClient) SetError ¶
func (m *MockGRPCClient) SetError(err error)
SetError configures the mock to return an error.
func (*MockGRPCClient) SetInvokeFunc ¶
func (m *MockGRPCClient) SetInvokeFunc(f func(ctx context.Context, req *InvokeRequest) (*InvokeResponse, error))
SetInvokeFunc sets a custom invoke function.
func (*MockGRPCClient) SetStartJobFunc ¶
func (m *MockGRPCClient) SetStartJobFunc(f func(ctx context.Context, req *InvokeRequest) (string, error))
SetStartJobFunc sets a custom start job function.
func (*MockGRPCClient) SetStreamEvents ¶
func (m *MockGRPCClient) SetStreamEvents(events []*JobEvent)
SetStreamEvents sets the events to return from stream.
func (*MockGRPCClient) StartJob ¶
func (m *MockGRPCClient) StartJob(ctx context.Context, req *InvokeRequest) (string, error)
StartJob starts a mock job.
type MockServiceContext ¶
type MockServiceContext struct {
Config *MockConfig
// contains filtered or unexported fields
}
MockServiceContext is a mock implementation of ServiceContext for testing.
func NewMockServiceContext ¶
func NewMockServiceContext() *MockServiceContext
NewMockServiceContext creates a new mock service context.
func (*MockServiceContext) AddFunction ¶
func (m *MockServiceContext) AddFunction(id string, handler interface{})
AddFunction adds a function to the mock context.
func (*MockServiceContext) FunctionCount ¶
func (m *MockServiceContext) FunctionCount() int
FunctionCount returns the number of registered functions.
func (*MockServiceContext) GetActiveJobs ¶
func (m *MockServiceContext) GetActiveJobs() int
GetActiveJobs returns the number of active jobs.
func (*MockServiceContext) GetFunctions ¶
func (m *MockServiceContext) GetFunctions() map[string]interface{}
GetFunctions returns all registered functions.
func (*MockServiceContext) GetLastHeartbeat ¶
func (m *MockServiceContext) GetLastHeartbeat() time.Time
GetLastHeartbeat returns the last heartbeat timestamp.
func (*MockServiceContext) GetRegisteredAt ¶
func (m *MockServiceContext) GetRegisteredAt() time.Time
GetRegisteredAt returns the registration timestamp.
func (*MockServiceContext) IsRunning ¶
func (m *MockServiceContext) IsRunning() bool
IsRunning returns the running state.
func (*MockServiceContext) SetActiveJobs ¶
func (m *MockServiceContext) SetActiveJobs(count int)
SetActiveJobs sets the number of active jobs.
func (*MockServiceContext) SetConfig ¶
func (m *MockServiceContext) SetConfig(config *MockConfig)
SetConfig sets the mock configuration.
func (*MockServiceContext) SetLastHeartbeat ¶
func (m *MockServiceContext) SetLastHeartbeat(t time.Time)
SetLastHeartbeat sets the last heartbeat timestamp.
func (*MockServiceContext) SetRegisteredAt ¶
func (m *MockServiceContext) SetRegisteredAt(t time.Time)
SetRegisteredAt sets the registration timestamp.
func (*MockServiceContext) SetRunning ¶
func (m *MockServiceContext) SetRunning(running bool)
SetRunning sets the running state.
func (*MockServiceContext) SetStartTime ¶
func (m *MockServiceContext) SetStartTime(t time.Time)
SetStartTime sets the start time for uptime calculation.
func (*MockServiceContext) Uptime ¶
func (m *MockServiceContext) Uptime() time.Duration
Uptime returns the mock uptime duration.