mock

package
v0.0.0-...-bcf15ee Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mock provides common mock implementations for testing

Index

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

type CronScheduler struct {
	Jobs               []string
	ExecuteImmediately bool
}

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

func (*CronScheduler) Start

func (c *CronScheduler) Start(ctx context.Context) error

Start starts the scheduler

func (*CronScheduler) Stop

func (c *CronScheduler) Stop(ctx context.Context) error

Stop stops the scheduler

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 LogLevel

type LogLevel int

LogLevel represents logging severity levels

const (
	// These are placeholder values - adjust them according to actual requirements
	LogDebug LogLevel = iota
	LogInfo
	LogWarning
	LogError
	LogFatal
)

type Logger

type Logger struct {
	LogEntries []string
}

Logger implements a mock logger

func (*Logger) Debug

func (m *Logger) Debug(msg string, args ...interface{})

Debug implements the Logger interface

func (*Logger) Error

func (m *Logger) Error(msg string, args ...interface{})

Error implements the Logger interface

func (*Logger) Info

func (m *Logger) Info(msg string, args ...interface{})

Info implements the Logger interface

func (*Logger) Warn

func (m *Logger) Warn(msg string, args ...interface{})

Warn implements the Logger interface

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

func (*MockCronScheduler) Stop

func (m *MockCronScheduler) Stop() error

Stop stops 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

func (*TestScheduler) Start

func (s *TestScheduler) Start(ctx context.Context) error

Start starts the scheduler

func (*TestScheduler) Stop

func (s *TestScheduler) Stop(ctx context.Context) error

Stop stops the scheduler

Jump to

Keyboard shortcuts

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