diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-04 08:21:18 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-04 08:21:18 +0300 |
| commit | bef02f9f9908c65fea5472f04e534a5fba577502 (patch) | |
| tree | b5f234379fb618216c2e598b622b8934a28eb67a /internal/hexaicli/testhelpers_test.go | |
| parent | 2a38b3ed4cc95d342af539723c03ad075c0acb84 (diff) | |
tests: quick wins to raise coverage
- internal/logging >90%
- internal/hexaicli >90%
- keep next targets: internal/lsp, internal/llm
Diffstat (limited to 'internal/hexaicli/testhelpers_test.go')
| -rw-r--r-- | internal/hexaicli/testhelpers_test.go | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/internal/hexaicli/testhelpers_test.go b/internal/hexaicli/testhelpers_test.go index 97b531d..1f75916 100644 --- a/internal/hexaicli/testhelpers_test.go +++ b/internal/hexaicli/testhelpers_test.go @@ -2,12 +2,13 @@ package hexaicli import ( - "context" - "os" - "path/filepath" - "testing" + "context" + "encoding/json" + "os" + "path/filepath" + "testing" - "codeberg.org/snonux/hexai/internal/llm" + "codeberg.org/snonux/hexai/internal/llm" ) // setStdin sets os.Stdin from a string and returns a restore func and reader. @@ -54,9 +55,21 @@ type fakeStreamer struct { } func (s *fakeStreamer) ChatStream(ctx context.Context, messages []llm.Message, onDelta func(string), opts ...llm.RequestOption) error { - s.sMsgs = append([]llm.Message{}, messages...) - for _, c := range s.chunks { - onDelta(c) - } - return nil + s.sMsgs = append([]llm.Message{}, messages...) + for _, c := range s.chunks { + onDelta(c) + } + return nil +} + +// small JSON writer for tests +func writeJSON(t *testing.T, path string, v any) { + t.Helper() + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { t.Fatalf("mkdir: %v", err) } + f, err := os.Create(path) + if err != nil { t.Fatalf("create: %v", err) } + defer f.Close() + if err := json.NewEncoder(f).Encode(v); err != nil { t.Fatalf("encode: %v", err) } } + +func testingTempDir(t *testing.T) string { t.Helper(); return t.TempDir() } |
