Documentation
¶
Overview ¶
Package configtest provides a mock implementation of the config provider API for use in tests. The mock records all calls and allows configuring per-method behavior via function fields.
mock := &configtest.MockConfig{}
mock.GetFn = func(key string) any {
if key == "database.host" {
return "localhost"
}
return nil
}
For tests that just need a working config seeded with known values, use NewMockConfigWithValues, which delegates to a real *config.Config under the hood so Get/Find/Bind retain their normal semantics.
Index ¶
- type Call
- type MockConfig
- func (m *MockConfig) Bind(dest any, options ...config.BindOption) error
- func (m *MockConfig) CallCount(method string) int
- func (m *MockConfig) Find(key string) (value any, exist bool)
- func (m *MockConfig) Get(key string) any
- func (m *MockConfig) Reset()
- func (m *MockConfig) Set(key string, value any)
- func (m *MockConfig) SetDefault(key string, value any)
- func (m *MockConfig) SetDefaults(values any) error
- func (m *MockConfig) Values() map[string]any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockConfig ¶
type MockConfig struct {
SetDefaultFn func(key string, value any)
SetDefaultsFn func(values any) error
SetFn func(key string, value any)
BindFn func(dest any, options ...config.BindOption) error
GetFn func(key string) any
FindFn func(key string) (any, bool)
ValuesFn func() map[string]any
Calls []Call
// contains filtered or unexported fields
}
MockConfig is a configurable mock that structurally satisfies the gas.ConfigProvider interface. Each method delegates to its corresponding Fn field if set, otherwise returns the zero value. All calls are recorded in the Calls slice for assertions.
func NewMockConfigWithValues ¶
func NewMockConfigWithValues(values map[string]any) (*MockConfig, error)
NewMockConfigWithValues returns a MockConfig whose Fn fields delegate to a real *config.Config seeded with the provided values. This preserves real key-normalization, Get/Find, and Bind semantics while still recording calls and allowing individual Fn fields to be overridden afterwards.
func (*MockConfig) Bind ¶
func (m *MockConfig) Bind(dest any, options ...config.BindOption) error
Bind records the call and delegates to BindFn if set.
func (*MockConfig) CallCount ¶
func (m *MockConfig) CallCount(method string) int
CallCount returns the number of times the given method was called.
func (*MockConfig) Find ¶
func (m *MockConfig) Find(key string) (value any, exist bool)
Find records the call and delegates to FindFn if set.
func (*MockConfig) Get ¶
func (m *MockConfig) Get(key string) any
Get records the call and delegates to GetFn if set.
func (*MockConfig) Set ¶
func (m *MockConfig) Set(key string, value any)
Set records the call and delegates to SetFn if set.
func (*MockConfig) SetDefault ¶
func (m *MockConfig) SetDefault(key string, value any)
SetDefault records the call and delegates to SetDefaultFn if set.
func (*MockConfig) SetDefaults ¶
func (m *MockConfig) SetDefaults(values any) error
SetDefaults records the call and delegates to SetDefaultsFn if set.
func (*MockConfig) Values ¶
func (m *MockConfig) Values() map[string]any
Values records the call and delegates to ValuesFn if set.