Documentation
¶
Overview ¶
Package mock provides a mock implementations needed for testing.
Index ¶
- Constants
- type KeyNotFound
- type SlogHandler
- func (mock *SlogHandler) Enabled(_ context.Context, _ slog.Level) bool
- func (mock *SlogHandler) Handle(_ context.Context, record slog.Record) error
- func (mock *SlogHandler) LogCallsCount(lvl slog.Level) int
- func (mock *SlogHandler) ValueAt(callNo uint, forKey string) any
- func (mock *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (mock *SlogHandler) WithGroup(_ string) slog.Handler
Constants ¶
const Any uint = 0
Any can be passed to [MockHandler.ValueAt] as call index, in case the order is not known/important/multiple logs happen concurrently.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyNotFound ¶
type KeyNotFound struct{}
KeyNotFound is the type of value returned by SlogHandler.ValueAt in case the searched key is not found.
type SlogHandler ¶
type SlogHandler struct {
// contains filtered or unexported fields
}
SlogHandler is a mock for slog.Handler, which allows us to intercept the log calls and assert on the log content.
func NewSlogHandler ¶
func NewSlogHandler() *SlogHandler
NewSlogHandler instantiates a new SlogHandler object.
func (*SlogHandler) Handle ¶
Handle intercepts the log calls and stores the log content for later assertions.
func (*SlogHandler) LogCallsCount ¶
func (mock *SlogHandler) LogCallsCount(lvl slog.Level) int
LogCallsCount returns the no. of times Error/Warn/Info/Debug/Log was called. Differentiate methods calls count by passing appropriate level.
func (*SlogHandler) ValueAt ¶
func (mock *SlogHandler) ValueAt(callNo uint, forKey string) any
ValueAt returns the value for a key at given call, in case no callback was set. Calls are positive numbers (starting with 1). If the order of the calls is not known/important/multiple logs happen concurrently, you can use Any. If the key is not found, KeyNotFound is returned.