diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-04 08:13:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-04 08:13:45 +0300 |
| commit | 2a38b3ed4cc95d342af539723c03ad075c0acb84 (patch) | |
| tree | adb1547c9e57080c32e22f153fa5042a644aaebc /internal/logging/logging_test.go | |
| parent | 2c14978bdbd17c764bd88234e3edc3435d329924 (diff) | |
logging: add tests for Logf/Preview and ChatLogger.LogStart; achieve >90% package coverage
Diffstat (limited to 'internal/logging/logging_test.go')
| -rw-r--r-- | internal/logging/logging_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go new file mode 100644 index 0000000..be8c93f --- /dev/null +++ b/internal/logging/logging_test.go @@ -0,0 +1,48 @@ +package logging + +import ( + "bytes" + "log" + "strings" + "testing" +) + +func TestLogf_WithBindAndPreview(t *testing.T) { + var buf bytes.Buffer + l := log.New(&buf, "", 0) + Bind(l) + + SetLogPreviewLimit(5) + if got := PreviewForLog("abcdef"); got != "abcde…" { + t.Fatalf("preview truncation failed: %q", got) + } + if got := PreviewForLog("abcd"); got != "abcd" { + t.Fatalf("preview (no trunc) failed: %q", got) + } + SetLogPreviewLimit(0) + if got := PreviewForLog("abcdef"); got != "abcdef" { + t.Fatalf("preview unlimited failed: %q", got) + } + + Logf("mod ", "hello %s", "world") + out := buf.String() + if !strings.Contains(out, "hello world") || !strings.Contains(out, AnsiBase) || !strings.Contains(out, AnsiReset) { + t.Fatalf("log output missing parts: %q", out) + } +} + +func TestChatLogger_LogStart(t *testing.T) { + var buf bytes.Buffer + Bind(log.New(&buf, "", 0)) + SetLogPreviewLimit(3) + cl := NewChatLogger("prov") + msgs := []struct{ Role, Content string }{{"user", "abcdef"}, {"assistant", "xyz"}} + cl.LogStart(true, "m", 0.2, 128, []string{"END"}, msgs) + out := buf.String() + if !strings.Contains(out, "stream start model=m") || !strings.Contains(out, "messages=2") { + t.Fatalf("missing header log: %q", out) + } + if !strings.Contains(out, "msg[0] role=user") || !strings.Contains(out, "preview=") { + t.Fatalf("missing message logs: %q", out) + } +} |
