testutil

package
v0.324.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestContext added in v0.175.0

func NewTestContext(opts ...TestContextOpt) context.Context

NewTestContext returns a context suitable for use within unit tests. The context comes equipped with the following: 1. Logger To modify the test context further, pass additional TestContextOpt values.

Types

type TestContextOpt added in v0.175.0

type TestContextOpt interface {
	Apply(ctx context.Context) context.Context
}

TestContextOpt is an interface to help configure the test context.

func WithConfig added in v0.175.0

func WithConfig(cfg *config.DefaultConfig) TestContextOpt

WithConfig returns a TestContextOpt that adds the given configuration into the test context.

func WithLogLevel added in v0.175.0

func WithLogLevel(level log.Level) TestContextOpt

WithLogLevel returns a TestContextOpt that sets the log level within the test context.

func WithLogPayload added in v0.175.0

func WithLogPayload(log bool) TestContextOpt

WithLogPayload returns a TestContextOpt that sets the configuration option within the test context to log the payload contents or not.

type TestLogEntries added in v0.175.0

type TestLogEntries struct {
	Entries []TestLogEntry
}

type TestLogEntry added in v0.175.0

type TestLogEntry struct {
	Level   log.Level
	Message string
	Error   error
	Fields  map[string]interface{}
}

type TestLogger added in v0.175.0

type TestLogger struct {
	Level  log.Level
	Fields map[string]interface{}
	// contains filtered or unexported fields
}

The TestLogger is an implementation of log.Logger suitable for use within unit tests. Provision with NewTestLogger or NewTestContext.

func NewTestContextWithLogger added in v0.175.0

func NewTestContextWithLogger(opts ...TestContextOpt) (context.Context, *TestLogger)

NewTestContext returns a context (and logger) suitable for use within unit tests. The context comes equipped with the following: 1. Logger To modify the test context further, pass additional TestContextOpt values.

func NewTestLogger added in v0.175.0

func NewTestLogger() *TestLogger

func (*TestLogger) Debug added in v0.175.0

func (l *TestLogger) Debug(message string)

func (*TestLogger) Entries added in v0.175.0

func (l *TestLogger) Entries() []TestLogEntry

func (*TestLogger) EntryCount added in v0.175.0

func (l *TestLogger) EntryCount() int

func (*TestLogger) Error added in v0.175.0

func (l *TestLogger) Error(err error, message string)

func (*TestLogger) Info added in v0.175.0

func (l *TestLogger) Info(message string)

func (*TestLogger) Inject added in v0.175.0

func (l *TestLogger) Inject(ctx context.Context) (context.Context, func(ctx context.Context) log.Logger)

func (*TestLogger) LastEntry added in v0.175.0

func (l *TestLogger) LastEntry() *TestLogEntry

func (*TestLogger) WithDuration added in v0.175.0

func (l *TestLogger) WithDuration(key string, value time.Duration) log.Logger

func (*TestLogger) WithInt added in v0.175.0

func (l *TestLogger) WithInt(key string, value int) log.Logger

func (*TestLogger) WithLevel added in v0.175.0

func (l *TestLogger) WithLevel(level log.Level) log.Logger

func (*TestLogger) WithStr added in v0.175.0

func (l *TestLogger) WithStr(key string, value string) log.Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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