Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLoggerWithCtx ¶
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 ¶
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 ¶
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.