Documentation ¶
Index ¶
- func Empty() fieldEmpty
- func Equal(expected interface{}) fieldEqual
- func EqualError(expected string) fieldEqualError
- func EqualErrorf(expected string, args ...interface{}) fieldEqualError
- func Equalf(expected string, args ...interface{}) fieldEqual
- func False() fieldFalse
- func IsType(expected interface{}) fieldIsType
- func Nil() fieldNil
- func NotEqual(expected interface{}) fieldNotEqual
- func Regexp(expected *regexp.Regexp) fieldRegexp
- func True() fieldTrue
- type ExpectedLog
- type Field
- type FieldValue
- type Fields
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Error(msg string)
- func (l *Logger) ExpectDebug(msg string) *ExpectedLog
- func (l *Logger) ExpectError(msg string) *ExpectedLog
- func (l *Logger) ExpectInfo(msg string) *ExpectedLog
- func (l *Logger) ExpectWarn(msg string) *ExpectedLog
- func (l *Logger) Flush() error
- func (l *Logger) Info(msg string)
- func (l *Logger) Warn(msg string)
- func (l *Logger) WithError(err error) logging.Logger
- func (l *Logger) WithField(key string, value interface{}) logging.Logger
- func (l *Logger) WithFields(fields logging.Fields) logging.Logger
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
func Equal(expected interface{}) fieldEqual
Equal asserts that a log field value is equal to the given expected value.
func EqualError ¶
func EqualError(expected string) fieldEqualError
EqualError asserts that a log field value is an error with a message equal to the given expected value.
func EqualErrorf ¶
func EqualErrorf(expected string, args ...interface{}) fieldEqualError
EqualErrorf asserts that a log field value is an error with a message equal to the given expected value with arguments substituted in.
func Equalf ¶
func Equalf(expected string, args ...interface{}) fieldEqual
Equalf asserts that a log field value is equal to the given expected string value with arguments substituted in.
func IsType ¶
func IsType(expected interface{}) fieldIsType
IsType asserts that a log field value matched the type of the given expected value.
func NotEqual ¶
func NotEqual(expected interface{}) fieldNotEqual
NotEqual asserts that a log field value is not equal to the given expected value.
Types ¶
type ExpectedLog ¶
type ExpectedLog struct {
// contains filtered or unexported fields
}
ExpectedLog describes a single log statement that is expected to be generated by tested code.
func (*ExpectedLog) String ¶
func (l *ExpectedLog) String() string
func (*ExpectedLog) WithError ¶
func (l *ExpectedLog) WithError(value ...FieldValue) *ExpectedLog
WithField adds an expectation upon a log field added using WithError. There must be at least one expectation on each log field.
func (*ExpectedLog) WithField ¶
func (l *ExpectedLog) WithField(key string, value ...FieldValue) *ExpectedLog
WithField adds an expectation upon a single log field. There must be at least one expectation on each log field.
func (*ExpectedLog) WithFields ¶
func (l *ExpectedLog) WithFields(fields ...*Field) *ExpectedLog
WithFields adds expectations upon multiple log fields. There must be at least one expectation on each log field.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a log field with a key and number of expectations upon the log field value.
func NewField ¶
func NewField(key string, value ...FieldValue) *Field
NewField creates a new Field instance.
type FieldValue ¶
FieldValue is used to assert that a log field value matches a given expectation.
There is currently no "Any" implementation to allow any value to be present in a log field, partly to encourage good behavior when asserting against log fields, but also to help identify new Value implementations to cover additional use cases.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a in-memory mock implementation of the logging.Logger interface.
func NewLogger ¶
NewLogger creates a new Logger instance.
Any registered expectations are automatically verified when the test completes along with identification of unfulfilled expectations.
func (*Logger) ExpectDebug ¶
func (l *Logger) ExpectDebug(msg string) *ExpectedLog
ExpectDebug adds an expectation for a log message at DEBUG level. If you wish to set expectations on DEBUG logs, you must also use the AssertDebugLogs option when calling NewLogger. Expectations on log fields can be added using the returned ExpectedLog.
func (*Logger) ExpectError ¶
func (l *Logger) ExpectError(msg string) *ExpectedLog
ExpectError adds an expectation for a log message at ERROR level. Expectations on log fields can be added using the returned ExpectedLog.
func (*Logger) ExpectInfo ¶
func (l *Logger) ExpectInfo(msg string) *ExpectedLog
ExpectInfo adds an expectation for a log message at INFO level. Expectations on log fields can be added using the returned ExpectedLog.
func (*Logger) ExpectWarn ¶
func (l *Logger) ExpectWarn(msg string) *ExpectedLog
ExpectWarn adds an expectation for a log message at WARN level. Expectations on log fields can be added using the returned ExpectedLog.
func (*Logger) Flush ¶
Flush flushes any pending log statements. This is a no-op as logs are stored in memory.
type Option ¶
type Option = func(*loggerOptions)
Option implementations can be used to configure a new Logger instance.
func AssertDebugLogs ¶
func AssertDebugLogs() Option
AssertDebugLogs enables assertions against DEBUG level logs. If this is not used, DEBUG level logs are ignored by Logger.AssertExpectations.
func AssertWithoutOrder ¶
func AssertWithoutOrder() Option
AssertWithoutOrder enables assertions in any order for each level of logs. This allows assertions on logs pushed to the same underlying logger from multiple goroutines (as the order the logs are generated in may be nondeterministic).
Each generated log will be compared with each expectation until one matches, at which point that expectation is removed from the available list, as such the expectations must be specific enough to match only the single log they are intended to match.
func SkipAssert ¶
func SkipAssert() Option
SkipAssert disables all assertions such that any or no logs can be produced without being checked.
This is generally inappropriate for unit testing, but may be useful for contract testing where only the API inputs and outputs are of interest.