2021-03-23 13:46:11 +11:00
|
|
|
// Copyright 2020-21 PJ Engineering and Business Solutions Pty. Ltd. All rights reserved.
|
|
|
|
|
2020-10-04 10:25:55 +11:00
|
|
|
package googlesearch_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/rocketlaunchr/google-search"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ctx = context.Background()
|
|
|
|
|
|
|
|
func TestSearch(t *testing.T) {
|
|
|
|
|
|
|
|
q := "Hello World"
|
|
|
|
|
|
|
|
opts := googlesearch.SearchOptions{
|
2021-07-01 12:03:01 +10:00
|
|
|
Limit: 20,
|
2020-10-04 10:25:55 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
returnLinks, err := googlesearch.Search(ctx, q, opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("something went wrong: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(returnLinks) == 0 {
|
|
|
|
t.Errorf("no results returned: %v", returnLinks)
|
|
|
|
}
|
2022-05-24 11:34:47 +10:00
|
|
|
|
|
|
|
noURL := 0
|
|
|
|
noTitle := 0
|
|
|
|
noDesc := 0
|
|
|
|
|
|
|
|
for _, res := range returnLinks {
|
|
|
|
if res.URL == "" {
|
|
|
|
noURL++
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.Title == "" {
|
|
|
|
noTitle++
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.Description == "" {
|
|
|
|
noDesc++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if noURL == len(returnLinks) || noTitle == len(returnLinks) || noDesc == len(returnLinks) {
|
|
|
|
t.Errorf("google dom changed")
|
|
|
|
}
|
2020-10-04 10:25:55 +11:00
|
|
|
}
|