Documentation
¶
Overview ¶
Package mock provides common mock implementations for testing
Index ¶
- type ApplicationWithReset
- type ConfigProvider
- type CronScheduler
- type CronSchedulerInterface
- type LogLevel
- type Logger
- type MockCronScheduler
- func (m *MockCronScheduler) Init() error
- func (m *MockCronScheduler) Name() string
- func (m *MockCronScheduler) RunJob(jobName string) bool
- func (m *MockCronScheduler) Schedule(jobName, cronSchedule string, jobFunc func())
- func (m *MockCronScheduler) Start() error
- func (m *MockCronScheduler) Stop() error
- type TestScheduler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplicationWithReset ¶
type ApplicationWithReset struct {
modular.Application
}
ApplicationWithReset extends the standard application with testing utilities
func NewTestApplication ¶
func NewTestApplication() *ApplicationWithReset
NewTestApplication creates a new application instance suitable for testing
func (*ApplicationWithReset) ResetServices ¶
func (a *ApplicationWithReset) ResetServices()
ResetServices clears any registered services for clean testing
type ConfigProvider ¶
type ConfigProvider struct {
ConfigData map[string]interface{}
}
ConfigProvider implements a mock config provider
func NewConfigProvider ¶
func NewConfigProvider() *ConfigProvider
NewConfigProvider creates a new mock config provider with proper env structure
func (*ConfigProvider) GetConfig ¶
func (m *ConfigProvider) GetConfig() any
GetConfig implements the ConfigProvider interface
func (*ConfigProvider) UpdateConfigWithProperEnvStructure ¶
func (m *ConfigProvider) UpdateConfigWithProperEnvStructure() *ConfigProvider
UpdateConfigWithProperEnvStructure updates the configuration with proper environment structure This method fixes the "env: env: invalid structure" error that occurs with golobby config
func (*ConfigProvider) WithWorkflow ¶
func (m *ConfigProvider) WithWorkflow(name string, config map[string]interface{}) *ConfigProvider
WithWorkflow adds a workflow configuration to the mock config
type CronScheduler ¶
CronScheduler is a mock implementation of a cron scheduler
func NewCronScheduler ¶
func NewCronScheduler() *CronScheduler
NewCronScheduler creates a new instance of the mock scheduler
func (*CronScheduler) AddJob ¶
func (c *CronScheduler) AddJob(spec string, job interface{}) error
AddJob adds a job to the scheduler
func (*CronScheduler) SetExecuteImmediately ¶
func (c *CronScheduler) SetExecuteImmediately(immediate bool)
SetExecuteImmediately sets whether jobs should execute immediately when added
type CronSchedulerInterface ¶
type CronSchedulerInterface interface {
Name() string
Init() error
Start() error
Stop() error
Schedule(jobName, cronSchedule string, jobFunc func())
}
CronSchedulerInterface defines the interface that matches the module.CronScheduler allowing us to avoid the direct import of the module package
func GetScheduler ¶
func GetScheduler() CronSchedulerInterface
GetScheduler returns a mock scheduler instance that implements the interface
type Logger ¶
type Logger struct {
LogEntries []string
}
Logger implements a mock logger
type MockCronScheduler ¶
type MockCronScheduler struct {
// contains filtered or unexported fields
}
MockCronScheduler is our implementation that can be used in tests
func NewMockCronScheduler ¶
func NewMockCronScheduler(name string) *MockCronScheduler
NewMockCronScheduler creates a new mock scheduler implementation
func (*MockCronScheduler) Init ¶
func (m *MockCronScheduler) Init() error
Init initializes the scheduler
func (*MockCronScheduler) Name ¶
func (m *MockCronScheduler) Name() string
Name returns the scheduler name
func (*MockCronScheduler) RunJob ¶
func (m *MockCronScheduler) RunJob(jobName string) bool
RunJob executes a scheduled job by name (for testing)
func (*MockCronScheduler) Schedule ¶
func (m *MockCronScheduler) Schedule(jobName, cronSchedule string, jobFunc func())
Schedule adds a job to the scheduler
func (*MockCronScheduler) Start ¶
func (m *MockCronScheduler) Start() error
Start starts the scheduler
type TestScheduler ¶
type TestScheduler struct {
SchedulerName string // Changed from Name to SchedulerName to avoid conflict
CronExpression string
JobsAdded []string
JobFunctions []interface{}
Started bool
Stopped bool
StartError error
StopError error
AddJobError error
InitializerCalled bool
}
TestScheduler is a mock implementation for testing schedulers
func NewTestScheduler ¶
func NewTestScheduler(name, cronExpression string) *TestScheduler
NewTestScheduler creates a new test scheduler
func (*TestScheduler) AddJob ¶
func (s *TestScheduler) AddJob(spec string, job interface{}) error
AddJob adds a job to the scheduler
func (*TestScheduler) Init ¶
func (s *TestScheduler) Init(registry map[string]interface{}) error
Init initializes the scheduler
func (*TestScheduler) Name ¶
func (s *TestScheduler) Name() string
Name returns the name of the scheduler