-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_search_baidu_test.go
More file actions
46 lines (38 loc) · 903 Bytes
/
example_search_baidu_test.go
File metadata and controls
46 lines (38 loc) · 903 Bytes
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
package serpapi
import (
"testing"
"github.com/serpapi/serpapi-golang"
)
// example test for baidu engine
// doc: https://serpapi.com/baidu-search-api
//
func TestBaidu(t *testing.T) {
if shoulSkip() {
t.Skip("SERPSERPAPI_KEY required")
return
}
auth := map[string]string{
"api_key": *getApiKey(),
}
client := serpapi.NewClient(auth)
parameter := map[string]string{
"engine": "baidu",
"q": "coffee", }
rsp, err := client.Search(parameter)
if err != nil {
t.Error("unexpected error", err)
return
}
if rsp["search_metadata"].(map[string]interface{})["status"] != "Success" {
t.Error("bad status")
return
}
if rsp["organic_results"] == nil {
t.Error("key is not found: organic_results")
return
}
if len(rsp["organic_results"].([]interface{})) < 5 {
t.Error("expect more than 5 organic_results")
return
}
}