(t *testing.T)
| 268 | } |
| 269 | |
| 270 | func TestSugarFieldsInvalidPairs(t *testing.T) { |
| 271 | withSugar(t, DebugLevel, nil, func(logger *SugaredLogger, logs *observer.ObservedLogs) { |
| 272 | logger.With(42, "foo", []string{"bar"}, "baz").Info("") |
| 273 | output := logs.AllUntimed() |
| 274 | |
| 275 | // Double-check that the actual message was logged. |
| 276 | require.Equal(t, 2, len(output), "Unexpected number of entries logged.") |
| 277 | require.Equal(t, observer.LoggedEntry{Context: []Field{}}, output[1], "Unexpected non-error log entry.") |
| 278 | |
| 279 | // Assert that the error message's structured fields serialize properly. |
| 280 | require.Equal(t, 1, len(output[0].Context), "Expected one field in error entry context.") |
| 281 | enc := zapcore.NewMapObjectEncoder() |
| 282 | output[0].Context[0].AddTo(enc) |
| 283 | assert.Equal(t, []interface{}{ |
| 284 | map[string]interface{}{"position": int64(0), "key": int64(42), "value": "foo"}, |
| 285 | map[string]interface{}{"position": int64(2), "key": []interface{}{"bar"}, "value": "baz"}, |
| 286 | }, enc.Fields["invalid"], "Unexpected output when logging invalid key-value pairs.") |
| 287 | }) |
| 288 | } |
| 289 | |
| 290 | func TestSugarStructuredLogging(t *testing.T) { |
| 291 | tests := []struct { |
nothing calls this directly
no test coverage detected