testing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package testing provides a mock Logger and assertion helpers for use in tests.

Types and helpers are re-exports of the internal testutil package, so that the same implementation is used internally and by external consumers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertLogContains

func AssertLogContains(reporter TB, mock *MockLogger, level logger.Level, contains string)

AssertLogContains verifies that at least one log at the given level contains the expected substring.

func AssertLogCount

func AssertLogCount(reporter TB, mock *MockLogger, expected int)

AssertLogCount verifies the number of captured logs.

func AssertLogField

func AssertLogField(reporter TB, mock *MockLogger, level logger.Level, key string, value any)

AssertLogField verifies that at least one log at the given level has the specified field.

func AssertLogLevel

func AssertLogLevel(reporter TB, mock *MockLogger, level logger.Level)

AssertLogLevel verifies that at least one log at the given level exists.

func AssertLogMessage

func AssertLogMessage(reporter TB, mock *MockLogger, level logger.Level, message string)

AssertLogMessage verifies that at least one log has the exact message.

func AssertNoLogs

func AssertNoLogs(reporter TB, mock *MockLogger)

AssertNoLogs verifies that no logs were captured.

func AssertNoLogsAtLevel

func AssertNoLogsAtLevel(reporter TB, mock *MockLogger, level logger.Level)

AssertNoLogsAtLevel verifies that no logs were captured at the given level.

Types

type Entry

type Entry = testutil.Entry

Entry is a single captured log record.

type MockLogger

type MockLogger = testutil.MockLogger

MockLogger implements logger.Logger by recording all log calls. It is safe for concurrent use and shares its entry store with derived loggers returned by WithFields, WithContext, and WithLevel.

func NewMockLogger

func NewMockLogger() *MockLogger

NewMockLogger returns a ready-to-use MockLogger.

type TB

type TB = testutil.TB

TB is the common interface shared by *testing.T and *testing.B used by assertion helpers so they can be called from both tests and benchmarks.

Jump to

Keyboard shortcuts

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