-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwingly_search_client_test.go
81 lines (61 loc) · 1.71 KB
/
twingly_search_client_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package twingly_search_client
import (
"reflect"
"testing"
)
func TestNew(t *testing.T) {
testClient, _ := New()
got := reflect.TypeOf(testClient)
want := reflect.TypeOf(client{})
if got != want {
t.Errorf("Expected a type of %q, got %q", want, got)
}
}
func TestSetUserAgent(t *testing.T) {
testClient, _ := New()
testClient.SetUserAgent("Testing Company/1.0")
got := testClient.UserAgent
want := "Testing Company/1.0"
if got != want {
t.Errorf("Expected a type of %q, got %q", want, got)
}
}
func TestAddQuery(t *testing.T) {
testClient, _ := New()
testClient.AddQuery("golang page-size:10")
got := testClient.query["q"]
want := []string{"golang page-size:10"}
if !reflect.DeepEqual(got, want) {
t.Errorf("Expected %q, got %q", reflect.ValueOf(want), reflect.ValueOf(got))
}
}
func TestBuildUrl(t *testing.T) {
t.Run("it builds url without a query", func(t *testing.T) {
client, _ := New()
builtUrl := client.buildUrl()
got := builtUrl.String()
want := "https://api.twingly.com/blog/search/api/v3/search?apikey="
if got != want {
t.Errorf("Expected %q, got %q", want, got)
}
})
t.Run("it builds url with a query", func(t *testing.T) {
client, _ := New()
client.AddQuery("programming in golang page-size:1")
builtUrl := client.buildUrl()
got := builtUrl.String()
want := "https://api.twingly.com/blog/search/api/v3/search?apikey=&q=programming+in+golang+page-size%3A1"
if got != want {
t.Errorf("Expected %q, got %q", want, got)
}
})
}
func TestExecuteQuery(t *testing.T) {
client, _ := New()
result, _ := client.ExecuteQuery()
got := reflect.TypeOf(result)
want := reflect.TypeOf(TwinglyResponse{})
if got != want {
t.Errorf("Expected %q, got %q", want, got)
}
}