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

Function TestErrorEncoding

zapcore/error_test.go:80–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

78}
79
80func TestErrorEncoding(t *testing.T) {
81 tests := []struct {
82 key string
83 iface any
84 want map[string]any
85 }{
86 {
87 key: "k",
88 iface: errTooManyUsers(2),
89 want: map[string]any{
90 "k": "2 too many users",
91 },
92 },
93 {
94 key: "k",
95 iface: errTooFewUsers(2),
96 want: map[string]any{
97 "k": "2 too few users",
98 "kVerbose": "verbose: 2 too few users",
99 },
100 },
101 {
102 key: "err",
103 iface: multierr.Combine(
104 errors.New("foo"),
105 errors.New("bar"),
106 errors.New("baz"),
107 ),
108 want: map[string]any{
109 "err": "foo; bar; baz",
110 "errCauses": []any{
111 map[string]any{"error": "foo"},
112 map[string]any{"error": "bar"},
113 map[string]any{"error": "baz"},
114 },
115 },
116 },
117 {
118 key: "e",
119 iface: customMultierr{},
120 want: map[string]any{
121 "e": "great sadness",
122 "eCauses": []any{
123 map[string]any{"error": "foo"},
124 map[string]any{
125 "error": "bar; baz",
126 "errorCauses": []any{
127 map[string]any{"error": "bar"},
128 map[string]any{"error": "baz"},
129 },
130 },
131 },
132 },
133 },
134 {
135 key: "k",
136 iface: fmt.Errorf("failed: %w", errors.New("egad")),
137 want: map[string]any{

Callers

nothing calls this directly

Calls 5

AddToMethod · 0.95
errTooManyUsersTypeAlias · 0.85
errTooFewUsersTypeAlias · 0.85
NewMapObjectEncoderFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected