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

Function TestFieldAddingError

zapcore/field_test.go:105–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func TestFieldAddingError(t *testing.T) {
106 var empty interface{}
107 tests := []struct {
108 t FieldType
109 iface interface{}
110 want interface{}
111 err string
112 }{
113 {t: ArrayMarshalerType, iface: users(-1), want: []interface{}{}, err: "too few users"},
114 {t: ObjectMarshalerType, iface: users(-1), want: map[string]interface{}{}, err: "too few users"},
115 {t: InlineMarshalerType, iface: users(-1), want: nil, err: "too few users"},
116 {t: StringerType, iface: obj{}, want: empty, err: "PANIC=interface conversion: zapcore_test.obj is not fmt.Stringer: missing method String"},
117 {t: StringerType, iface: &obj{1}, want: empty, err: "PANIC=panic with string"},
118 {t: StringerType, iface: &obj{2}, want: empty, err: "PANIC=panic with error"},
119 {t: StringerType, iface: &obj{3}, want: empty, err: "PANIC=<nil>"},
120 {t: ErrorType, iface: &errObj{kind: 1}, want: empty, err: "PANIC=panic in Error() method"},
121 }
122 for _, tt := range tests {
123 f := Field{Key: "k", Interface: tt.iface, Type: tt.t}
124 enc := NewMapObjectEncoder()
125 assert.NotPanics(t, func() { f.AddTo(enc) }, "Unexpected panic when adding fields returns an error.")
126 assert.Equal(t, tt.want, enc.Fields["k"], "On error, expected zero value in field.Key.")
127 assert.Equal(t, tt.err, enc.Fields["kError"], "Expected error message in log context.")
128 }
129}
130
131func TestFields(t *testing.T) {
132 tests := []struct {

Callers

nothing calls this directly

Calls 3

AddToMethod · 0.95
NewMapObjectEncoderFunction · 0.85
usersTypeAlias · 0.70

Tested by

no test coverage detected