|
1
|
package llm |
|
2
|
|
|
3
|
import ( |
|
4
|
"testing" |
|
5
|
) |
|
6
|
|
|
7
|
func TestNew(t *testing.T) { |
|
8
|
tests := []struct { |
|
9
|
name string |
|
10
|
cfg BackendConfig |
|
11
|
wantErr bool |
|
12
|
}{ |
|
13
|
{ |
|
14
|
name: "openai", |
|
15
|
cfg: BackendConfig{Backend: "openai", APIKey: "key"}, |
|
16
|
}, |
|
17
|
{ |
|
18
|
name: "anthropic", |
|
19
|
cfg: BackendConfig{Backend: "anthropic", APIKey: "key"}, |
|
20
|
}, |
|
21
|
{ |
|
22
|
name: "gemini", |
|
23
|
cfg: BackendConfig{Backend: "gemini", APIKey: "key"}, |
|
24
|
}, |
|
25
|
{ |
|
26
|
name: "ollama", |
|
27
|
cfg: BackendConfig{Backend: "ollama", BaseURL: "http://localhost:11434"}, |
|
28
|
}, |
|
29
|
{ |
|
30
|
name: "bedrock", |
|
31
|
cfg: BackendConfig{Backend: "bedrock", Region: "us-east-1", AWSKeyID: "key", AWSSecretKey: "secret"}, |
|
32
|
}, |
|
33
|
{ |
|
34
|
name: "unknown", |
|
35
|
cfg: BackendConfig{Backend: "unknown"}, |
|
36
|
wantErr: true, |
|
37
|
}, |
|
38
|
} |
|
39
|
|
|
40
|
for _, tt := range tests { |
|
41
|
t.Run(tt.name, func(t *testing.T) { |
|
42
|
_, err := New(tt.cfg) |
|
43
|
if (err != nil) != tt.wantErr { |
|
44
|
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr) |
|
45
|
} |
|
46
|
}) |
|
47
|
} |
|
48
|
} |
|
49
|
|
|
50
|
func TestBackendNames(t *testing.T) { |
|
51
|
names := BackendNames() |
|
52
|
if len(names) == 0 { |
|
53
|
t.Error("expected non-empty backend names") |
|
54
|
} |
|
55
|
|
|
56
|
foundGemini := false |
|
57
|
for _, n := range names { |
|
58
|
if n == "gemini" { |
|
59
|
foundGemini = true |
|
60
|
break |
|
61
|
} |
|
62
|
} |
|
63
|
if !foundGemini { |
|
64
|
t.Error("expected gemini in backend names") |
|
65
|
} |
|
66
|
} |
|
67
|
|
|
68
|
func TestKnownBackends(t *testing.T) { |
|
69
|
if _, ok := KnownBackends["openai"]; !ok { |
|
70
|
t.Error("expected openai in known backends") |
|
71
|
} |
|
72
|
} |
|
73
|
|