testpolylog

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoggerWithCtx

func NewLoggerWithCtx(
	ctx context.Context,
	level polylog.Level,
) (polylog.Logger, context.Context)

func RunEventMethodTests

func RunEventMethodTests(
	t *testing.T,
	level polylog.Level,
	tests []EventMethodTestCase,
	newLoggerAndOutput NewLoggerAndOutputFn,
	newEventWithLevel NewEventWithLevelFn,
	getExpectedLevelOutputContains func(level polylog.Level) string,
)

RunEventMethodTests runs a set of tests for a given level.

Types

type EventFuncSpy

type EventFuncSpy struct{ mock.Mock }

EventFuncSpy is a mock which implements a #Fn() method that is intended to be used in tests to assert that the function passed to polylog.Event#Func() is called with the expected arg(s).

func (*EventFuncSpy) Fn

func (m *EventFuncSpy) Fn(event polylog.Event)

Fn is a mock method which can be asserted on via the mock.Mock API. See: https://pkg.go.dev/github.com/stretchr/testify@v1.8.4/mock#Mock.

type EventMethodTestCase

type EventMethodTestCase struct {
	// Msg is the string to pass to polylog.Event#Msg(), which will be called
	// after the event method under test. Usage of Msg is mutually exclusive
	// with MsgFmt. If neither are provided, then polylog.Event#Send() is called
	// after the event method instead.
	Msg string

	// MsgFmt is the format string to pass to polylog.Event#Msgf(), which will
	// be called on the event returned from the event method under test. Usage
	// of MsgFmt is mutually exclusive with Msg. If neither are provided, then
	// polylog.Event#Send() is called after the event method instead.
	MsgFmt string

	// MsgFmtArgs are the args to pass to polylog.Event#Msgf(). It is an error
	// to provide MsgFmtArgs without also providing MsgFmt or while providing
	// Msg.
	MsgFmtArgs []any

	// Key is the key to pass to the event method under test.
	Key string

	// Value is the value to pass to the event method under test.
	Value any

	// EventMethodName is the name of the event method to call on the logger.
	EventMethodName string

	// ExpectedOutputContains is the string that is expected to be contained
	// in the log output.
	ExpectedOutputContains string
}

EventMethodTestCase is a test case for expressing and exercising polylog.Event methods in a concise way.

type NewEventWithLevelFn

type NewEventWithLevelFn func(
	*testing.T,
	polylog.Logger,
	polylog.Level,
) polylog.Event

NewEventWithLevelFn is called in the test helper to create a new event at the given level from the given logger. It is useful for decoupling test helpers from a specific logger implementation so that we can call `logger.<LevelMethod>() without knowing the concrete logger type nor the level.

type NewLoggerAndOutputFn

type NewLoggerAndOutputFn func(
	*testing.T,
	polylog.Level,
	...polylog.LoggerOption,
) (polylog.Logger, *bytes.Buffer)

NewLoggerAndOutputFn is called in the test helper to create a new logger configured with the given level and options. It returns the logger and the buffer to which the logger writes. It is useful for decoupling test helpers from a specific logger implementation and reducing boilerplate code in various tests.

Jump to

Keyboard shortcuts

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