spy

package
v0.0.0-...-d3bedcd Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package spy provides an implementation of go-sdk.logger that helps test logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogDummy

func NewLogDummy() *logrus.Entry

NewLogDummy returns dummy logger which discards logged messages on the fly. Useful when logger is required as dependency in unit testing.

Types

type EntryAssertFormatter

type EntryAssertFormatter struct {
	Underlying logrus.Formatter
	// contains filtered or unexported fields
}

EntryAssertFormatter is a log formatter, which gather all logged entries

func (*EntryAssertFormatter) AllEntriesMatches

func (f *EntryAssertFormatter) AllEntriesMatches(matcher func(entry logrus.Entry) bool) bool

AllEntriesMatches iterates over all stored entries and execute given matcher on it. Return true only if all entries was successful matched

func (*EntryAssertFormatter) AnyMatches

func (f *EntryAssertFormatter) AnyMatches(matcher func(entry logrus.Entry) bool) bool

AnyMatches iterates over all stored entries and execute given matcher on it. Return true if any entries was successful matched

func (*EntryAssertFormatter) Format

func (f *EntryAssertFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format appends each entry to entries slice

type LogSink

type LogSink struct {
	RawLogger *logrus.Logger
	Logger    *logrus.Entry
	// contains filtered or unexported fields
}

LogSink is a helper construct for testing logging in unit tests. Beware: all methods are working on copies of of original messages buffer and are safe for multiple uses.

func NewLogSink

func NewLogSink() *LogSink

NewLogSink is a factory for LogSink

func (*LogSink) AssertErrorLogged

func (s *LogSink) AssertErrorLogged(t *testing.T, errorExpected error)

AssertErrorLogged checks whatever a specific string was logged as error.

Compared elements: level, message

Wrapped errors are supported as long as original error message ends up in resulting one.

func (*LogSink) AssertLogged

func (s *LogSink) AssertLogged(t *testing.T, level logrus.Level, message string)

AssertLogged checks whatever a specific string was logged at a specific level.

Compared elements: level, message

Beware: we are checking for sub-strings and not for the exact match.

func (*LogSink) AssertNotLogged

func (s *LogSink) AssertNotLogged(t *testing.T, level logrus.Level, message string)

AssertNotLogged checks whatever a specific string was not logged at a specific level.

Compared elements: level, message

Beware: we are checking for sub-strings and not for the exact match.

func (*LogSink) DumpAll

func (s *LogSink) DumpAll() []string

DumpAll returns all logged messages.

Jump to

Keyboard shortcuts

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