go-rag/ollama_test.go
Claude acb987a01d
test: add Phase 1 pure-function unit tests (18.4% -> 38.8% coverage)
Add comprehensive unit tests for all pure functions that require no
external services (Qdrant, Ollama). Coverage of testable functions
now at 100% for FormatResults*, Default*Config, EmbedDimension,
valueToGo, Model, ChunkID, and ChunkMarkdown edge cases.

New test files:
- query_test.go: FormatResultsText, FormatResultsContext, FormatResultsJSON,
  DefaultQueryConfig (18 tests)
- ollama_test.go: DefaultOllamaConfig, EmbedDimension, Model (8 tests)
- qdrant_test.go: DefaultQdrantConfig, pointIDToString, valueToGo,
  Point/SearchResult structs (24 tests)

Extended chunk_test.go with edge cases:
- Empty input, whitespace-only, single newline
- Headers with no body content
- Unicode/emoji text with rune-safe overlap verification
- Very long single paragraph
- Config boundary conditions (zero/negative size, overlap >= size)
- Sequential chunk indexing
- ChunkID rune truncation with multibyte characters
- DefaultChunkConfig, DefaultIngestConfig

Co-Authored-By: Charon <developers@lethean.io>
2026-02-20 00:02:52 +00:00

88 lines
2 KiB
Go

package rag
import (
"testing"
"github.com/stretchr/testify/assert"
)
// --- DefaultOllamaConfig tests ---
func TestDefaultOllamaConfig(t *testing.T) {
t.Run("returns expected default values", func(t *testing.T) {
cfg := DefaultOllamaConfig()
assert.Equal(t, "localhost", cfg.Host, "default host should be localhost")
assert.Equal(t, 11434, cfg.Port, "default port should be 11434")
assert.Equal(t, "nomic-embed-text", cfg.Model, "default model should be nomic-embed-text")
})
}
// --- EmbedDimension tests ---
func TestEmbedDimension(t *testing.T) {
tests := []struct {
name string
model string
expected uint64
}{
{
name: "nomic-embed-text returns 768",
model: "nomic-embed-text",
expected: 768,
},
{
name: "mxbai-embed-large returns 1024",
model: "mxbai-embed-large",
expected: 1024,
},
{
name: "all-minilm returns 384",
model: "all-minilm",
expected: 384,
},
{
name: "unknown model defaults to 768",
model: "some-unknown-model",
expected: 768,
},
{
name: "empty model name defaults to 768",
model: "",
expected: 768,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// Construct OllamaClient directly with the config to avoid needing a live server.
// We only set the config field; client is nil but EmbedDimension does not use it.
client := &OllamaClient{
config: OllamaConfig{Model: tc.model},
}
dim := client.EmbedDimension()
assert.Equal(t, tc.expected, dim)
})
}
}
// --- Model tests ---
func TestModel(t *testing.T) {
t.Run("returns the configured model name", func(t *testing.T) {
client := &OllamaClient{
config: OllamaConfig{Model: "nomic-embed-text"},
}
assert.Equal(t, "nomic-embed-text", client.Model())
})
t.Run("returns custom model name", func(t *testing.T) {
client := &OllamaClient{
config: OllamaConfig{Model: "custom-model"},
}
assert.Equal(t, "custom-model", client.Model())
})
}