mock

package
v0.0.0-...-439e5cb Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mock provides a mock implementations needed for testing.

Index

Constants

View Source
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) Enabled

func (mock *SlogHandler) Enabled(_ context.Context, _ slog.Level) bool

Enabled returns true, as we want to intercept all log calls.

func (*SlogHandler) Handle

func (mock *SlogHandler) Handle(_ context.Context, record slog.Record) error

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.

func (*SlogHandler) WithAttrs

func (mock *SlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs adds the given attributes to the handler, so that they are included in all subsequent log calls.

func (*SlogHandler) WithGroup

func (mock *SlogHandler) WithGroup(_ string) slog.Handler

WithGroup is a no-op for SlogHandler, as groups are not relevant for our tests.

Jump to

Keyboard shortcuts

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