MCPcopy
hub / github.com/uber-go/zap / TestErrorArrayConstructor

Function TestErrorArrayConstructor

error_test.go:58–79  ·  error_test.go::TestErrorArrayConstructor
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestErrorArrayConstructor(t *testing.T) {
59 tests := []struct {
60 desc string
61 field Field
62 expected []interface{}
63 }{
64 {"empty errors", Errors("", []error{}), []interface{}{}},
65 {
66 "errors",
67 Errors("", []error{nil, errors.New("foo"), nil, errors.New("bar")}),
68 []interface{}{map[string]interface{}{"error": "foo"}, map[string]interface{}{"error": "bar"}},
69 },
70 }
71
72 for _, tt := range tests {
73 enc := zapcore.NewMapObjectEncoder()
74 tt.field.Key = "k"
75 tt.field.AddTo(enc)
76 assert.Equal(t, tt.expected, enc.Fields["k"], "%s: unexpected map contents.", tt.desc)
77 assert.Equal(t, 1, len(enc.Fields), "%s: found extra keys in map: %v", tt.desc, enc.Fields)
78 }
79}
80
81func TestErrorsArraysHandleRichErrors(t *testing.T) {
82 errs := []error{fmt.Errorf("egad")}

Callers

nothing calls this directly

Calls 3

NewMapObjectEncoderFunction · 0.92
ErrorsFunction · 0.85
AddToMethod · 0.80

Tested by

no test coverage detected