MCPcopy Create free account
hub / github.com/compozy/agh / TestNewWithFileRotation

Function TestNewWithFileRotation

internal/logger/logger_test.go:33–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestNewWithFileRotation(t *testing.T) {
34 t.Parallel()
35
36 t.Run("ShouldRotateStructuredLogFileWhenSizeCapIsReached", func(t *testing.T) {
37 t.Parallel()
38
39 logFile := filepath.Join(t.TempDir(), "logs", "agh.log")
40 log, closeFn, err := New(
41 WithLevel("info"),
42 WithFile(logFile),
43 WithFileRotation(FileRotationConfig{MaxSizeMB: 1, MaxBackups: 2, MaxAgeDays: 1}),
44 WithMirrorToStderr(false),
45 )
46 if err != nil {
47 t.Fatalf("New() error = %v", err)
48 }
49 payload := strings.Repeat("x", 2048)
50 for i := range 700 {
51 log.Info("rotation-check", "index", i, "payload", payload)
52 }
53 if err := closeFn(); err != nil {
54 t.Fatalf("closeFn() error = %v", err)
55 }
56 entries, err := os.ReadDir(filepath.Dir(logFile))
57 if err != nil {
58 t.Fatalf("ReadDir() error = %v", err)
59 }
60 rotated := false
61 for _, entry := range entries {
62 name := entry.Name()
63 if name != filepath.Base(logFile) && strings.HasPrefix(name, "agh-") && strings.HasSuffix(name, ".log") {
64 rotated = true
65 }
66 }
67 if !rotated {
68 t.Fatalf("rotated log file not found in %v", entries)
69 }
70 })
71}
72
73func TestParseLevelRejectsUnsupportedValue(t *testing.T) {
74 t.Parallel()

Callers

nothing calls this directly

Calls 8

WithLevelFunction · 0.85
WithFileFunction · 0.85
WithFileRotationFunction · 0.85
WithMirrorToStderrFunction · 0.85
NewFunction · 0.70
RunMethod · 0.65
InfoMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected