Documentation ¶
Overview ¶
Package zltest provides facilities to test zerolog log messages.
Index ¶
- type Entries
- func (ets Entries) ExpBool(key string, exp bool)
- func (ets Entries) ExpDur(key string, exp time.Duration)
- func (ets Entries) ExpEntry(n int) *Entry
- func (ets Entries) ExpErr(exp error)
- func (ets Entries) ExpError(exp string)
- func (ets Entries) ExpLen(want int)
- func (ets Entries) ExpMsg(exp string)
- func (ets Entries) ExpNum(key string, exp float64)
- func (ets Entries) ExpStr(key string, exp string)
- func (ets Entries) ExpStrContains(key string, exp string)
- func (ets Entries) ExpTime(key string, exp time.Time)
- func (ets Entries) Get() []*Entry
- func (ets Entries) NotExpBool(key string, exp bool)
- func (ets Entries) NotExpDur(key string, exp time.Duration)
- func (ets Entries) NotExpErr(exp error)
- func (ets Entries) NotExpError(exp string)
- func (ets Entries) NotExpMsg(exp string)
- func (ets Entries) NotExpNum(key string, exp float64)
- func (ets Entries) NotExpStr(key string, exp string)
- func (ets Entries) NotExpTime(key string, exp time.Time)
- func (ets Entries) Print()
- type Entry
- func (ent *Entry) Bool(key string) (bool, KeyStatus)
- func (ent *Entry) ExpBool(key string, exp bool)
- func (ent *Entry) ExpDur(key string, exp time.Duration)
- func (ent *Entry) ExpErr(exp error)
- func (ent *Entry) ExpError(exp string)
- func (ent *Entry) ExpKey(key string)
- func (ent *Entry) ExpLevel(exp zerolog.Level)
- func (ent *Entry) ExpLoggedWithin(exp time.Time, diff time.Duration)
- func (ent *Entry) ExpMsg(exp string)
- func (ent *Entry) ExpNum(key string, exp float64)
- func (ent *Entry) ExpNumKeys(n int)
- func (ent *Entry) ExpStr(key string, exp string)
- func (ent *Entry) ExpStrContains(key string, exp string)
- func (ent *Entry) ExpTime(key string, exp time.Time)
- func (ent *Entry) ExpTimeWithin(key string, exp time.Time, diff time.Duration)
- func (ent *Entry) Float64(key string) (float64, KeyStatus)
- func (ent *Entry) Map(key string) (map[string]interface{}, KeyStatus)
- func (ent *Entry) NotExpKey(key string)
- func (ent *Entry) Str(key string) (string, KeyStatus)
- func (ent *Entry) String() string
- func (ent *Entry) Time(key string) (time.Time, KeyStatus)
- type KeyStatus
- type T
- type Tester
- func (tst *Tester) Entries() Entries
- func (tst *Tester) Filter(level zerolog.Level) Entries
- func (tst *Tester) FirstEntry() *Entry
- func (tst *Tester) LastEntry() *Entry
- func (tst *Tester) Len() int
- func (tst *Tester) Logger() zerolog.Logger
- func (tst *Tester) Reset()
- func (tst *Tester) String() string
- func (tst *Tester) Write(p []byte) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entries ¶ added in v0.3.0
type Entries struct {
// contains filtered or unexported fields
}
Entries represents collection of zerolog log entries.
func (Entries) ExpBool ¶ added in v0.3.0
ExpBool tests that at lest one entry has a field key, its value is boolean and equal to exp.
func (Entries) ExpDur ¶ added in v0.3.0
ExpDur tests that at least one log entry has a field key and its value is equal to exp time.Duration. The duration vale in the entry is multiplied by zerolog.DurationFieldUnit before the comparison.
func (Entries) ExpErr ¶ added in v0.11.0
ExpErr tests that at least one log entry error field (zerolog.ErrorFieldName) is equal to exp error message.
func (Entries) ExpError ¶ added in v0.9.0
ExpError tests that at least one log entry error field (zerolog.ErrorFieldName) is equal to exp.
func (Entries) ExpMsg ¶ added in v0.3.0
ExpMsg tests that at least one log entry message field (zerolog.MessageFieldName) is equal to exp.
func (Entries) ExpNum ¶ added in v0.3.0
ExpNum tests that at least one log entry has a field key and its numerical value is equal to exp.
func (Entries) ExpStr ¶ added in v0.3.0
ExpStr tests that at least one log entry has a field key, its value is a string, and it's equal to exp.
func (Entries) ExpStrContains ¶ added in v0.8.0
ExpStrContains tests that at least one log entry has a field key, its value is a string, and it contains exp.
func (Entries) ExpTime ¶ added in v0.3.0
ExpTime tests that at least one log entry has a field key, its value is a string representing time in zerolog.TimeFieldFormat and it's equal to exp.
func (Entries) NotExpBool ¶ added in v0.3.0
NotExpBool tests that no log entry has a field key, its value is boolean and equal to exp.
func (Entries) NotExpDur ¶ added in v0.3.0
NotExpDur tests that no log entry has a field key and its value is equal to exp time.Duration. The duration vale in the entry is multiplied by zerolog.DurationFieldUnit before the comparison.
func (Entries) NotExpErr ¶ added in v0.11.0
NotExpErr tests that none of the log entry error fields (zerolog.ErrorFieldName) are equal to exp error message.
func (Entries) NotExpError ¶ added in v0.9.0
NotExpError tests that none of the log entry error fields (zerolog.ErrorFieldName) are equal to exp.
func (Entries) NotExpMsg ¶ added in v0.3.0
NotExpMsg tests that none of the log entry message fields (zerolog.MessageFieldName) are equal to exp.
func (Entries) NotExpNum ¶ added in v0.3.0
NotExpNum tests that at least one log entry has a field key and its numerical value is equal to exp.
func (Entries) NotExpStr ¶ added in v0.3.0
NotExpStr tests that no log entry has a field key, its value is a string, and it's equal to exp.
func (Entries) NotExpTime ¶ added in v0.3.0
NotExpTime tests that no one log entry has a field key, its value is a string representing time in zerolog.TimeFieldFormat and it's equal to exp.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry represents one zerolog log entry.
func (*Entry) ExpBool ¶
ExpBool tests log entry has a field key, its value is boolean and equal to exp.
func (*Entry) ExpDur ¶
ExpDur tests log entry has a field key and its value is equal to exp time.Duration. The duration vale in the entry is multiplied by zerolog.DurationFieldUnit before the comparison.
func (*Entry) ExpErr ¶ added in v0.11.0
ExpErr tests log entry message field (zerolog.ErrorFieldName) is equal to exp error message.
func (*Entry) ExpError ¶ added in v0.9.0
ExpError tests log entry message field (zerolog.ErrorFieldName) is equal to exp.
func (*Entry) ExpLevel ¶
ExpLevel tests log entry level field (zerolog.LevelFieldName) is equal to exp.
func (*Entry) ExpLoggedWithin ¶
ExpLoggedWithin tests log entry was logged at exp time. The actual time may be within +/- diff.
func (*Entry) ExpMsg ¶
ExpMsg tests log entry message field (zerolog.MessageFieldName) is equal to exp.
func (*Entry) ExpNum ¶
ExpNum tests log entry has a field key and its numerical value is equal to exp.
func (*Entry) ExpNumKeys ¶ added in v0.12.0
ExpNumKeys tests log entry has n keys.
func (*Entry) ExpStr ¶
ExpStr tests log entry has a field key, its value is a string, and it's equal to exp.
func (*Entry) ExpStrContains ¶ added in v0.8.0
ExpStrContains tests log entry has a field key, its value is a string, and it contains exp.
func (*Entry) ExpTime ¶
ExpTime tests log entry has a field key, its value is a string representing time in zerolog.TimeFieldFormat and it's equal to exp.
func (*Entry) ExpTimeWithin ¶
ExpTimeWithin tests log entry has a field key, its value is a string representing time in zerolog.TimeFieldFormat and it's equal to exp time. The actual time may be within +/- diff.
type KeyStatus ¶
type KeyStatus string
KeyStatus represents a status of searching and deserialization of a key in log entry.
const ( // KeyFound is used when a field key is found successfully. KeyFound KeyStatus = "KeyFound" // KeyBadType is used when a field key is found, but it's not of expected type. KeyBadType KeyStatus = "KeyBadType" // KeyMissing is used when a field key is not in the log entry. KeyMissing KeyStatus = "KeyMissing" // KeyBadFormat is used when a field key is found but its format is wrong. KeyBadFormat KeyStatus = "KeyBadFormat" )
type T ¶
type T interface { // Error is equivalent to Log followed by Fail. Error(args ...interface{}) // Errorf is equivalent to Logf followed by Fail. Errorf(format string, args ...interface{}) // Fatal is equivalent to Log followed by FailNow. Fatal(args ...interface{}) // Fatalf is equivalent to Logf followed by FailNow. Fatalf(format string, args ...interface{}) // Helper marks the calling function as a test helper function. // When printing file and line information, that function will be skipped. // Helper may be called simultaneously from multiple goroutines. Helper() // Log formats its arguments using default formatting, analogous to Println, // and records the text in the error log. For tests, the text will be printed only if // the test fails or the -test.v flag is set. For benchmarks, the text is always // printed to avoid having performance depend on the value of the -test.v flag. Log(args ...interface{}) // Logf formats its arguments according to the format, analogous to Printf, and // records the text in the error log. A final newline is added if not provided. For // tests, the text will be printed only if the test fails or the -test.v flag is // set. For benchmarks, the text is always printed to avoid having performance // depend on the value of the -test.v flag. Logf(format string, args ...interface{}) // Cleanup registers a function to be called when the test (or subtest) and all its // subtests complete. Cleanup functions will be called in last added, // first called order. Cleanup(func()) }
T is a subset of testing.TB interface. It's primarily used to test zltest package but can be used to implement custom actions to be taken on errors.
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
Tester represents zerolog log tester.
func (*Tester) Entries ¶
Entries returns all logged entries in the order they were logged. It calls Fatal if any of the log entries cannot be decoded or Scanner error.
func (*Tester) FirstEntry ¶
FirstEntry returns first log entry or nil if no log entries written to the Tester. It calls Fatal if any of the log entries cannot be decoded.
func (*Tester) LastEntry ¶
LastEntry returns last log entry or nil if no log entries written to the Tester. It calls Fatal if any of the log entries cannot be decoded.
func (*Tester) Logger ¶ added in v0.5.0
Logger returns zerolog.Logger using this tester as io.Writer.