mirror of
https://github.com/karust/openserp.git
synced 2026-09-08 12:43:56 +08:00
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:
+5
-22
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user