logtest

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

logtest provides the ability to test logs

Usage:

func MyTestFunc(t *testing.T) {
    logs := logTest.NewLogRecorder(t)
    defer logs.Close()
    .....
    if diff := logs.Diff(expected); diff != "" {
        t.Fatal("logs unexpected", diff);
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map(m log.Marshaler) map[string]interface{}

MarshalToMap uses the given arguments `MarshalLog` function to serialize it into a map, which it returns.

The serialization is similar to the one performed by logs. Any nesting is flattened by representing it as dot-separated key prefixes in a flat map.

Types

type LogRecorder

type LogRecorder struct {
	*testing.T

	sync.Mutex
	// contains filtered or unexported fields
}

LogRecorder holds the state

func NewLogRecorder

func NewLogRecorder(t *testing.T) *LogRecorder

NewLogRecorder starts a new log recorder.

Logs must be stopped by calling Close() on the recorder

func (*LogRecorder) Close

func (l *LogRecorder) Close()

Close closes the recorder

func (*LogRecorder) Entries

func (l *LogRecorder) Entries() []log.F

Entries returns the log entries.

func (*LogRecorder) Write

func (l *LogRecorder) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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