@@ -14,25 +14,50 @@ import (
1414
1515func TestNormalizeHost (t * testing.T ) {
1616 tests := []struct {
17- name string
18- input string
19- defaultHost string
20- want string
17+ name string
18+ input string
19+ want string
2120 }{
22- {"empty with default" , "" , "http://default:1234" , "http://default:1234" },
23- {"empty no default" , "" , "" , "" },
24- {"host only" , "localhost:11434" , "" , "https://localhost:11434" },
25- {"with http" , "http://localhost:11434" , "" , "http://localhost:11434" },
26- {"with https" , "https://ollama.example.com" , "" , "https://ollama.example.com" },
27- {"with trailing slash" , "http://localhost:11434/" , "" , "http://localhost:11434" },
28- {"ip address" , "192.168.1.100:11434" , "" , "https://192.168.1.100:11434" },
21+ {"host only" , "localhost:11434" , "https://localhost:11434" },
22+ {"with http" , "http://localhost:11434" , "http://localhost:11434" },
23+ {"with https" , "https://ollama.example.com" , "https://ollama.example.com" },
24+ {"with trailing slash" , "http://localhost:11434/" , "http://localhost:11434" },
25+ {"ip address" , "192.168.1.100:11434" , "https://192.168.1.100:11434" },
2926 }
3027
3128 for _ , tt := range tests {
3229 t .Run (tt .name , func (t * testing.T ) {
33- got := normalizeHost (tt .input , tt . defaultHost )
30+ got := normalizeHost (tt .input )
3431 if got != tt .want {
35- t .Errorf ("normalizeHost(%q, %q) = %q, want %q" , tt .input , tt .defaultHost , got , tt .want )
32+ t .Errorf ("normalizeHost(%q) = %q, want %q" , tt .input , got , tt .want )
33+ }
34+ })
35+ }
36+ }
37+
38+ func TestDetectProvider (t * testing.T ) {
39+ tests := []struct {
40+ name string
41+ host string
42+ wantProvider Provider
43+ wantPath string
44+ }{
45+ {"groq" , "https://api.groq.com" , ProviderGroq , consts .LLMPathGroq },
46+ {"openai" , "https://api.openai.com" , ProviderOpenAI , consts .LLMPathOpenAI },
47+ {"deepseek" , "https://api.deepseek.com" , ProviderOpenAI , consts .LLMPathOpenAI },
48+ {"mistral" , "https://api.mistral.ai" , ProviderOpenAI , consts .LLMPathOpenAI },
49+ {"openrouter" , "https://openrouter.ai" , ProviderOpenRouter , consts .LLMPathOpenRouter },
50+ {"unknown" , "https://custom-llm.example.com" , ProviderOpenAI , consts .LLMPathOpenAI },
51+ }
52+
53+ for _ , tt := range tests {
54+ t .Run (tt .name , func (t * testing.T ) {
55+ provider , path := detectProvider (tt .host )
56+ if provider != tt .wantProvider {
57+ t .Errorf ("detectProvider(%q) provider = %q, want %q" , tt .host , provider , tt .wantProvider )
58+ }
59+ if path != tt .wantPath {
60+ t .Errorf ("detectProvider(%q) path = %q, want %q" , tt .host , path , tt .wantPath )
3661 }
3762 })
3863 }
@@ -52,11 +77,11 @@ func TestNewClient_Defaults(t *testing.T) {
5277 if c .provider != ProviderOllama {
5378 t .Errorf ("provider = %q, want %q" , c .provider , ProviderOllama )
5479 }
55- if c .host != consts .LLMDefaultOllamaHost {
56- t .Errorf ("host = %q, want %q" , c .host , consts .LLMDefaultOllamaHost )
80+ if c .host != consts .LLMHostOllama {
81+ t .Errorf ("host = %q, want %q" , c .host , consts .LLMHostOllama )
5782 }
58- if c .model != consts .LLMDefaultOllamaModel {
59- t .Errorf ("model = %q, want %q" , c .model , consts .LLMDefaultOllamaModel )
83+ if c .model != consts .LLMModelOllama {
84+ t .Errorf ("model = %q, want %q" , c .model , consts .LLMModelOllama )
6085 }
6186 if c .timeout != consts .LLMDefaultRequestTimeout {
6287 t .Errorf ("timeout = %v, want %v" , c .timeout , consts .LLMDefaultRequestTimeout )
@@ -91,6 +116,7 @@ func TestGenerate_Ollama(t *testing.T) {
91116 c := & Client {
92117 provider : ProviderOllama ,
93118 host : server .URL ,
119+ apiPath : consts .LLMPathOllama ,
94120 timeout : 10 * time .Second ,
95121 retries : 0 ,
96122 }
@@ -120,6 +146,7 @@ func TestGenerate_Ollama(t *testing.T) {
120146 c := & Client {
121147 provider : ProviderOllama ,
122148 host : server .URL ,
149+ apiPath : consts .LLMPathOllama ,
123150 timeout : 10 * time .Second ,
124151 retries : 2 ,
125152 }
@@ -174,6 +201,7 @@ func TestGenerate_OpenAI(t *testing.T) {
174201 c := & Client {
175202 provider : ProviderGroq ,
176203 host : server .URL ,
204+ apiPath : consts .LLMPathGroq ,
177205 apiKey : "test-key" ,
178206 timeout : 10 * time .Second ,
179207 retries : 0 ,
@@ -201,6 +229,7 @@ func TestGenerate_OpenAI(t *testing.T) {
201229 c := & Client {
202230 provider : ProviderGroq ,
203231 host : server .URL ,
232+ apiPath : consts .LLMPathGroq ,
204233 apiKey : "test-key" ,
205234 timeout : 10 * time .Second ,
206235 retries : 0 ,
0 commit comments