test: a search engine out of its limit gives way to DuckDuckGo

This commit is contained in:
redtea committed 2026-10-16 10:53:53 +03:00
1 parent fdd0483286
commit 060975a443
1 file changed
+20
+20
View File
@@ -75,3 +75,23 @@ func TestSearchProviders(t *testing.T) {
t.Fatalf("fallback: %+v %v", rs, err)
}
}
// The chosen engine's limit spent (429 and the like): DuckDuckGo answers.
func TestSearchLimitFallsBack(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, `{"error":"rate limit"}`, http.StatusTooManyRequests)
}))
defer srv.Close()
old := ddgSearch
defer func() { ddgSearch = old }()
ddgSearch = func(ctx context.Context, q string, n int) ([]searchResult, error) {
return []searchResult{{Title: "DDG " + q}}, nil
}
braveURL, tavilyURL = srv.URL, srv.URL
for _, e := range []string{"brave", "tavily", "searxng"} {
rs, err := searchWith(context.Background(), searchConf{Engine: e, Key: "k", URL: srv.URL}, "x", 6)
if err != nil || len(rs) != 1 || rs[0].Title != "DDG x" {
t.Fatalf("%s: %+v %v", e, rs, err)
}
}
}