test

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package test provides helpers shared across the test suites, such as a logger that captures records for assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestLogger

func NewTestLogger() *slog.Logger

NewTestLogger creates a *slog.Logger backed by a capturing handler. The returned logger can be passed anywhere a *slog.Logger is expected. If you need to inspect captured log messages, use NewTestLoggerWithHandler instead.

Types

type Handler added in v0.20.0

type Handler struct {
	// contains filtered or unexported fields
}

Handler is a slog.Handler that captures log records for test assertions.

func NewHandler added in v0.20.0

func NewHandler() *Handler

NewHandler creates a new test handler that captures all log levels.

func NewTestLoggerWithHandler added in v0.20.0

func NewTestLoggerWithHandler() (*slog.Logger, *Handler)

NewTestLoggerWithHandler creates a *slog.Logger and returns both the logger and its Handler, allowing tests to inspect captured log messages.

func (*Handler) Clear added in v0.20.0

func (h *Handler) Clear()

Clear clears all captured messages.

func (*Handler) Enabled added in v0.20.0

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements slog.Handler.

func (*Handler) ErrorCount added in v0.20.0

func (h *Handler) ErrorCount() int

ErrorCount returns the number of error messages.

func (*Handler) GetMessages added in v0.20.0

func (h *Handler) GetMessages() []LogEntry

GetMessages returns all logged messages.

func (*Handler) Handle added in v0.20.0

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*Handler) HasError added in v0.20.0

func (h *Handler) HasError(substr string) bool

HasError checks if an error message containing substr was logged.

func (*Handler) HasMessage added in v0.20.0

func (h *Handler) HasMessage(substr string) bool

HasMessage checks if any message containing substr was logged.

func (*Handler) HasWarning added in v0.20.0

func (h *Handler) HasWarning(substr string) bool

HasWarning checks if a warning message containing substr was logged.

func (*Handler) MessageCount added in v0.20.0

func (h *Handler) MessageCount() int

MessageCount returns the total number of captured messages.

func (*Handler) WarningCount added in v0.20.0

func (h *Handler) WarningCount() int

WarningCount returns the number of warning messages.

func (*Handler) WithAttrs added in v0.20.0

func (h *Handler) WithAttrs(_ []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*Handler) WithGroup added in v0.20.0

func (h *Handler) WithGroup(_ string) slog.Handler

WithGroup implements slog.Handler.

type LogEntry

type LogEntry struct {
	Level   string
	Message string
}

LogEntry represents a single log message with its level.

Directories

Path Synopsis
Package testutil provides common test utilities for the Ofelia project.
Package testutil provides common test utilities for the Ofelia project.

Jump to

Keyboard shortcuts

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