MCPcopy
hub / github.com/rs/zerolog / TestArrayErrorMarshalFunc

Function TestArrayErrorMarshalFunc

error_marshal_test.go:42–224  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestArrayErrorMarshalFunc(t *testing.T) {
43 prefixed := func(s, prefix string) string {
44 if s == "null" {
45 return ""
46 }
47 return prefix + s + `,`
48 }
49 errs := []error{
50 nil,
51 fmt.Errorf("failure"),
52 loggableError{fmt.Errorf("whoops")},
53 nonLoggableError{fmt.Errorf("oops"), 402},
54 }
55 type testCase struct {
56 name string
57 marshal func(err error) interface{}
58 want []string
59 }
60 testCases := []testCase{
61 {
62 name: "default",
63 marshal: nil,
64 want: []string{`null`, `"failure"`, `{"l":"WHOOPS"}`, `"oops"`},
65 },
66 {
67 name: "string",
68 marshal: func(err error) interface{} {
69 if err == nil {
70 return nil
71 }
72 return err.Error()
73 },
74 want: []string{`null`, `"failure"`, `"whoops"`, `"oops"`},
75 },
76 {
77 name: "loggable",
78 marshal: func(err error) interface{} {
79 if err == nil {
80 return nil
81 }
82 return loggableError{err}
83 },
84 want: []string{`null`, `{"l":"FAILURE"}`, `{"l":"WHOOPS"}`, `{"l":"OOPS"}`},
85 },
86 {
87 name: "non-loggable",
88 marshal: func(err error) interface{} {
89 if err == nil {
90 return nil
91 }
92 return nonLoggableError{err, 404}
93 },
94 want: []string{`null`, `"failure"`, `"whoops"`, `"oops"`},
95 },
96 {
97 name: "interface",
98 marshal: func(err error) interface{} {
99 var some interfaceError

Callers

nothing calls this directly

Calls 15

ArrFunction · 0.85
NewFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
decodeObjectToStrFunction · 0.70
decodeIfBinaryToStringFunction · 0.70
RunMethod · 0.65
ErrMethod · 0.65
LogMethod · 0.65
ErrorMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected