This commit is contained in:
@@ -41,6 +41,35 @@ func TestTranslateQueryFallsBackToDictionaryWhenTranslateFails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslateSummaryToKoreanUsesGoogleAndCaches(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`[[["도시에서 웃는 커플","smiling couple in city",null,null,1]],null,"en"]`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
service := NewGeminiService("")
|
||||
service.Client = &http.Client{Timeout: 2 * time.Second}
|
||||
service.TranslateEndpoint = server.URL
|
||||
|
||||
first, err := service.TranslateSummaryToKorean("smiling couple in city")
|
||||
if err != nil {
|
||||
t.Fatalf("expected translation to succeed, got error: %v", err)
|
||||
}
|
||||
second, err := service.TranslateSummaryToKorean("smiling couple in city")
|
||||
if err != nil {
|
||||
t.Fatalf("expected cached translation to succeed, got error: %v", err)
|
||||
}
|
||||
if first != "도시에서 웃는 커플" || second != first {
|
||||
t.Fatalf("unexpected translated summary values: %q %q", first, second)
|
||||
}
|
||||
if requests != 1 {
|
||||
t.Fatalf("expected one upstream translation request due to cache, got %d", requests)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeKnownMediaPhrases(t *testing.T) {
|
||||
translated := translateKoreanMediaTerms("사이버 펑크 도시")
|
||||
if translated != "cyberpunk city" {
|
||||
|
||||
Reference in New Issue
Block a user