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

Function TestJSONEmptyConfig

zapcore/json_encoder_test.go:182–217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestJSONEmptyConfig(t *testing.T) {
183 tests := []struct {
184 name string
185 field zapcore.Field
186 expected string
187 }{
188 {
189 name: "time",
190 field: zap.Time("foo", time.Unix(1591287718, 0)), // 2020-06-04 09:21:58 -0700 PDT
191 expected: `{"foo": 1591287718000000000}`,
192 },
193 {
194 name: "duration",
195 field: zap.Duration("bar", time.Microsecond),
196 expected: `{"bar": 1000}`,
197 },
198 }
199
200 for _, tt := range tests {
201 t.Run(tt.name, func(t *testing.T) {
202 enc := zapcore.NewJSONEncoder(zapcore.EncoderConfig{})
203
204 buf, err := enc.EncodeEntry(zapcore.Entry{
205 Level: zapcore.DebugLevel,
206 Time: time.Now(),
207 LoggerName: "mylogger",
208 Message: "things happened",
209 }, []zapcore.Field{tt.field})
210 if assert.NoError(t, err, "Unexpected JSON encoding error.") {
211 assert.JSONEq(t, tt.expected, buf.String(), "Incorrect encoded JSON entry.")
212 }
213
214 buf.Free()
215 })
216 }
217}
218
219// Encodes any object into empty json '{}'
220type emptyReflectedEncoder struct {

Callers

nothing calls this directly

Calls 7

TimeFunction · 0.92
DurationFunction · 0.92
NewJSONEncoderFunction · 0.92
EncodeEntryMethod · 0.65
NowMethod · 0.65
StringMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected