diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-06 13:18:21 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-06 13:18:21 +0300 |
| commit | 5e966f50111adf6e2cb2683fe588f6fe033fa931 (patch) | |
| tree | 19ac2033483c2ac6147e8f44ac37f14e6a5c0cf7 /internal/logging/logging_test.go | |
| parent | 80e61812986573464cd24c4b3ffa605c4003146a (diff) | |
fix unit test coverage
Diffstat (limited to 'internal/logging/logging_test.go')
| -rw-r--r-- | internal/logging/logging_test.go | 58 |
1 files changed, 17 insertions, 41 deletions
diff --git a/internal/logging/logging_test.go b/internal/logging/logging_test.go index adeefde..716781e 100644 --- a/internal/logging/logging_test.go +++ b/internal/logging/logging_test.go @@ -1,48 +1,24 @@ package logging import ( - "bytes" - "log" - "strings" - "testing" + "bytes" + "log" + "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 TestPreviewAndLogfAndChatLogger(t *testing.T) { + var buf bytes.Buffer + Bind(log.New(&buf, "", 0)) + SetLogPreviewLimit(3) + if got := PreviewForLog("abcdef"); got != "abc…" { + t.Fatalf("preview wrong: %q", got) + } + Logf("unit ", "hello %s", "x") + cl := NewChatLogger("p") + cl.LogStart(true, "m", 0.5, 100, []string{"stop"}, []struct{ Role, Content string }{{"user", "hello"}}) + out := buf.String() + if out == "" || !bytes.Contains([]byte(out), []byte("start")) { + t.Fatalf("expected logged content, got %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) - } -} |
