(t *testing.T)
| 36 | ) |
| 37 | |
| 38 | func TestSugarWith(t *testing.T) { |
| 39 | // Convenience functions to create expected error logs. |
| 40 | ignored := func(msg interface{}) observer.LoggedEntry { |
| 41 | return observer.LoggedEntry{ |
| 42 | Entry: zapcore.Entry{Level: ErrorLevel, Message: _oddNumberErrMsg}, |
| 43 | Context: []Field{Any("ignored", msg)}, |
| 44 | } |
| 45 | } |
| 46 | nonString := func(pairs ...invalidPair) observer.LoggedEntry { |
| 47 | return observer.LoggedEntry{ |
| 48 | Entry: zapcore.Entry{Level: ErrorLevel, Message: _nonStringKeyErrMsg}, |
| 49 | Context: []Field{Array("invalid", invalidPairs(pairs))}, |
| 50 | } |
| 51 | } |
| 52 | ignoredError := func(err error) observer.LoggedEntry { |
| 53 | return observer.LoggedEntry{ |
| 54 | Entry: zapcore.Entry{Level: ErrorLevel, Message: _multipleErrMsg}, |
| 55 | Context: []Field{Error(err)}, |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | type withAny func(*SugaredLogger, ...interface{}) *SugaredLogger |
| 60 | withMethods := []withAny{(*SugaredLogger).With, (*SugaredLogger).WithLazy} |
| 61 | |
| 62 | tests := []struct { |
| 63 | desc string |
| 64 | args []interface{} |
| 65 | expected []Field |
| 66 | errLogs []observer.LoggedEntry |
| 67 | }{ |
| 68 | { |
| 69 | desc: "nil args", |
| 70 | args: nil, |
| 71 | expected: []Field{}, |
| 72 | errLogs: nil, |
| 73 | }, |
| 74 | { |
| 75 | desc: "empty slice of args", |
| 76 | args: []interface{}{}, |
| 77 | expected: []Field{}, |
| 78 | errLogs: nil, |
| 79 | }, |
| 80 | { |
| 81 | desc: "just a dangling key", |
| 82 | args: []interface{}{"should ignore"}, |
| 83 | expected: []Field{}, |
| 84 | errLogs: []observer.LoggedEntry{ignored("should ignore")}, |
| 85 | }, |
| 86 | { |
| 87 | desc: "well-formed key-value pairs", |
| 88 | args: []interface{}{"foo", 42, "true", "bar"}, |
| 89 | expected: []Field{Int("foo", 42), String("true", "bar")}, |
| 90 | errLogs: nil, |
| 91 | }, |
| 92 | { |
| 93 | desc: "just a structured field", |
| 94 | args: []interface{}{Int("foo", 42)}, |
| 95 | expected: []Field{Int("foo", 42)}, |
nothing calls this directly
no test coverage detected