(t *testing.T)
| 180 | } |
| 181 | |
| 182 | func 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 '{}' |
| 220 | type emptyReflectedEncoder struct { |
nothing calls this directly
no test coverage detected