MCPcopy
hub / github.com/kopia/kopia / TestLoggerMultipleLogs

Function TestLoggerMultipleLogs

internal/contentlog/contentlog_logger_test.go:415–460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

413}
414
415func TestLoggerMultipleLogs(t *testing.T) {
416 t.Run("handles multiple log entries", func(t *testing.T) {
417 var captured []byte
418
419 outputFunc := func(data []byte) {
420 captured = append(captured, data...)
421 }
422
423 logger := contentlog.NewLogger(outputFunc)
424 ctx := context.Background()
425
426 contentlog.Log(ctx, logger, "first message")
427 contentlog.Log1(ctx, logger, "second message", logparam.String("id", "123"))
428 contentlog.Log2(ctx, logger, "third message", logparam.Int("count", 5), logparam.Bool("flag", true))
429
430 require.NotEmpty(t, captured)
431
432 // Split by newlines to get individual log entries
433 lines := strings.Split(strings.TrimSpace(string(captured)), "\n")
434 require.Len(t, lines, 3)
435
436 // Check first entry
437 var entry1 map[string]any
438
439 err := json.Unmarshal([]byte(lines[0]), &entry1)
440 require.NoError(t, err)
441 require.Equal(t, "first message", entry1["m"])
442
443 // Check second entry
444 var entry2 map[string]any
445
446 err = json.Unmarshal([]byte(lines[1]), &entry2)
447 require.NoError(t, err)
448 require.Equal(t, "second message", entry2["m"])
449 require.Equal(t, "123", entry2["id"])
450
451 // Check third entry
452 var entry3 map[string]any
453
454 err = json.Unmarshal([]byte(lines[2]), &entry3)
455 require.NoError(t, err)
456 require.Equal(t, "third message", entry3["m"])
457 require.Equal(t, float64(5), entry3["count"])
458 require.Equal(t, true, entry3["flag"])
459 })
460}
461
462func TestLoggerErrorHandling(t *testing.T) {
463 t.Run("handles nil error parameter", func(t *testing.T) {

Callers

nothing calls this directly

Calls 10

NewLoggerFunction · 0.92
LogFunction · 0.92
Log1Function · 0.92
StringFunction · 0.92
Log2Function · 0.92
IntFunction · 0.92
BoolFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected