21
21
package zap
22
22
23
23
import (
24
+ "errors"
24
25
"testing"
25
26
26
27
"go.uber.org/zap/internal/exit"
@@ -46,6 +47,12 @@ func TestSugarWith(t *testing.T) {
46
47
Context : []Field {Array ("invalid" , invalidPairs (pairs ))},
47
48
}
48
49
}
50
+ ignoredError := func (err error ) observer.LoggedEntry {
51
+ return observer.LoggedEntry {
52
+ Entry : zapcore.Entry {Level : ErrorLevel , Message : _multipleErrMsg },
53
+ Context : []Field {Error (err )},
54
+ }
55
+ }
49
56
50
57
tests := []struct {
51
58
desc string
@@ -122,6 +129,15 @@ func TestSugarWith(t *testing.T) {
122
129
nonString (invalidPair {2 , true , "bar" }, invalidPair {5 , 42 , "reversed" }),
123
130
},
124
131
},
132
+ {
133
+ desc : "multiple errors" ,
134
+ args : []interface {}{errors .New ("first" ), errors .New ("second" ), errors .New ("third" )},
135
+ expected : []Field {Error (errors .New ("first" ))},
136
+ errLogs : []observer.LoggedEntry {
137
+ ignoredError (errors .New ("second" )),
138
+ ignoredError (errors .New ("third" )),
139
+ },
140
+ },
125
141
}
126
142
127
143
for _ , tt := range tests {
@@ -198,10 +214,13 @@ func TestSugarStructuredLogging(t *testing.T) {
198
214
}
199
215
200
216
// Common to all test cases.
201
- context := []interface {}{"foo" , "bar" }
202
- extra := []interface {}{"baz" , false }
203
- expectedFields := []Field {String ("foo" , "bar" ), Bool ("baz" , false )}
204
-
217
+ var (
218
+ err = errors .New ("qux" )
219
+ context = []interface {}{"foo" , "bar" }
220
+ extra = []interface {}{err , "baz" , false }
221
+ expectedFields = []Field {String ("foo" , "bar" ), Error (err ), Bool ("baz" , false )}
222
+ )
223
+
205
224
for _ , tt := range tests {
206
225
withSugar (t , DebugLevel , nil , func (logger * SugaredLogger , logs * observer.ObservedLogs ) {
207
226
logger .With (context ... ).Debugw (tt .msg , extra ... )
0 commit comments