Add integration tests for multiple search engines and enhance error handling

- Implement integration tests for Baidu, Bing, DuckDuckGo, Google, and Yandex.
- Refactor test utility functions to avoid core import cycles.
This commit is contained in:
Rustem Kamalov
2026-04-14 02:05:58 +03:00
parent de59d07d47
commit ecacfab4d6
10 changed files with 321 additions and 42 deletions
+5 -22
View File
@@ -5,36 +5,21 @@ package yandex
import (
"testing"
"time"
"github.com/karust/openserp/core"
"github.com/karust/openserp/testutil"
"github.com/karust/openserp/testutil/ithelper"
)
func createTestBrowser(t *testing.T) *core.Browser {
t.Helper()
opts := core.BrowserOpts{IsHeadless: false, IsLeakless: false, Timeout: time.Second * 15, LeavePageOpen: true}
b, err := core.NewBrowser(opts)
if err != nil {
t.Fatalf("failed to create test browser: %v", err)
}
return b
}
func TestSearchYandex(t *testing.T) {
testutil.RequireIntegration(t)
browser := createTestBrowser(t)
browser := ithelper.CreateBrowser(t)
yand := New(*browser, core.SearchEngineOptions{})
query := core.Query{Text: "HEY", Limit: 10}
results, err := yand.Search(query)
if err != nil {
if err == core.ErrSearchTimeout || err == core.ErrCaptcha {
t.Skipf("skipping unstable live yandex search result: %v", err)
}
t.Fatalf("Cannot [SearchYandex]: %s", err)
}
ithelper.HandleError(t, "yandex web search", err)
if len(results) == 0 {
t.Fatalf("[SearchYandex] returned empty result")
@@ -44,14 +29,12 @@ func TestSearchYandex(t *testing.T) {
func TestImageYandex(t *testing.T) {
testutil.RequireIntegration(t)
browser := createTestBrowser(t)
browser := ithelper.CreateBrowser(t)
yand := New(*browser, core.SearchEngineOptions{})
query := core.Query{Text: "furry tiger", Limit: 30}
results, err := yand.SearchImage(query)
if err != nil {
t.Fatalf("Cannot [ImageYandex]: %s", err)
}
ithelper.HandleError(t, "yandex image search", err)
if len(results) == 0 {
t.Fatalf("[ImageYandex] returned empty result")