lltest

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package lltest provides a TestTransport and TestLoggingLibrary for use in the main module's own tests. It's a private copy of transports/testing because the public package lives in its own Go module, and main importing it would create a require cycle.

Keep this file byte-for-byte equivalent to transports/testing/testing.go (modulo the package declaration). Any change here must be mirrored there and vice versa.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	transport.BaseConfig
	// Library is the TestLoggingLibrary to write into.
	// If nil, a new one is created automatically.
	Library *TestLoggingLibrary
}

Config holds configuration for TestTransport.

type LogLine

type LogLine struct {
	Level    loglayer.LogLevel
	Messages []any
	// Data holds the assembled fields + error map. Nil when neither were set.
	Data loglayer.Data
	// Metadata is the raw value passed to WithMetadata. Nil if not set.
	Metadata any
	// Ctx is the per-call context.Context attached via WithContext. Nil if not set.
	Ctx context.Context
	// Groups mirrors [loglayer.TransportParams.Groups].
	Groups []string
	// Schema mirrors [loglayer.TransportParams.Schema].
	Schema loglayer.Schema
	// Prefix mirrors [loglayer.TransportParams.Prefix]: the value
	// attached via WithPrefix, exposed verbatim. Empty when no
	// prefix was set on the emitting logger.
	Prefix string
}

LogLine is a single captured log entry. Fields are exposed directly so tests can assert on each piece independently rather than parsing a flattened arg list.

type TestLoggingLibrary

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

TestLoggingLibrary captures log lines for assertion in tests. All methods are safe for concurrent use.

func (*TestLoggingLibrary) ClearLines

func (lib *TestLoggingLibrary) ClearLines()

ClearLines removes all captured lines.

func (*TestLoggingLibrary) GetLastLine

func (lib *TestLoggingLibrary) GetLastLine() *LogLine

GetLastLine returns the most recently captured line without removing it, or nil if no lines have been captured.

func (*TestLoggingLibrary) Len

func (lib *TestLoggingLibrary) Len() int

Len returns the number of captured lines.

func (*TestLoggingLibrary) Lines

func (lib *TestLoggingLibrary) Lines() []LogLine

Lines returns a copy of all captured lines.

func (*TestLoggingLibrary) Log

func (lib *TestLoggingLibrary) Log(line LogLine)

Log records a log line.

func (*TestLoggingLibrary) PopLine

func (lib *TestLoggingLibrary) PopLine() *LogLine

PopLine removes and returns the most recently captured line, or nil if no lines have been captured.

type TestTransport

type TestTransport struct {
	transport.BaseTransport
	Library *TestLoggingLibrary
}

TestTransport is a transport that records all log entries into a TestLoggingLibrary.

func New

func New(cfg Config) *TestTransport

New creates a TestTransport. If cfg.Library is nil a fresh one is allocated.

func (*TestTransport) GetLoggerInstance

func (t *TestTransport) GetLoggerInstance() any

GetLoggerInstance returns the underlying TestLoggingLibrary.

func (*TestTransport) SendToLogger

func (t *TestTransport) SendToLogger(params loglayer.TransportParams)

SendToLogger implements loglayer.Transport.

Jump to

Keyboard shortcuts

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