1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package gui
import (
"testing"
"codeberg.org/snonux/totalrecall/internal/translation"
)
func TestDefaultConfigPrefersGeminiTranslationProvider(t *testing.T) {
config := DefaultConfig()
if config.TranslationProvider != translation.ProviderGemini {
t.Fatalf("DefaultConfig() translation provider = %q, want %q", config.TranslationProvider, translation.ProviderGemini)
}
}
func TestTranslationConfigForApp(t *testing.T) {
t.Parallel()
tests := []struct {
name string
config *Config
wantProv translation.Provider
wantOpen string
wantGoogle string
}{
{
name: "default to gemini when google key is available",
config: &Config{
GoogleAPIKey: "google-key",
},
wantProv: translation.ProviderGemini,
wantOpen: "",
wantGoogle: "google-key",
},
{
name: "fallback to openai when only openai key is available",
config: &Config{
OpenAIKey: "openai-key",
},
wantProv: translation.ProviderOpenAI,
wantOpen: "openai-key",
wantGoogle: "",
},
{
name: "honor explicit gemini provider",
config: &Config{
TranslationProvider: translation.ProviderGemini,
GoogleAPIKey: "google-key",
OpenAIKey: "openai-key",
},
wantProv: translation.ProviderGemini,
wantOpen: "openai-key",
wantGoogle: "google-key",
},
{
name: "honor explicit openai provider",
config: &Config{
TranslationProvider: translation.ProviderOpenAI,
OpenAIKey: "openai-key",
GoogleAPIKey: "google-key",
},
wantProv: translation.ProviderOpenAI,
wantOpen: "openai-key",
wantGoogle: "google-key",
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := translationConfigForApp(tt.config)
if got.Provider != tt.wantProv {
t.Fatalf("Provider = %q, want %q", got.Provider, tt.wantProv)
}
if got.OpenAIKey != tt.wantOpen {
t.Fatalf("OpenAIKey = %q, want %q", got.OpenAIKey, tt.wantOpen)
}
if got.GoogleAPIKey != tt.wantGoogle {
t.Fatalf("GoogleAPIKey = %q, want %q", got.GoogleAPIKey, tt.wantGoogle)
}
})
}
}
|