-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptions_test.go
More file actions
108 lines (81 loc) · 2.45 KB
/
Copy pathoptions_test.go
File metadata and controls
108 lines (81 loc) · 2.45 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package scraperapi
import (
"context"
"net/http"
"testing"
)
func TestWithContext(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithContext(context.WithValue(context.Background(), "foo", "bar"))(req)
actual := req.Context().Value("foo")
if actual != "bar" {
t.Errorf("expected %s, got %v", "bar", actual)
}
}
func TestWithRenderJS(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithRenderJS()(req)
expected := "true"
actual := req.URL.Query().Get("render")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}
func TestWithHeaders(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
expected := "application/json"
req = WithHeader("Content-Type", expected)(req)
actual := req.Header.Get("Content-Type")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
actual2 := req.URL.Query().Get("keep_headers")
if actual2 != "true" {
t.Errorf("expected %s, got %v", "true", actual2)
}
}
func TestWithSessionNumber(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithSessionNumber("150")(req)
expected := "150"
actual := req.URL.Query().Get("session_number")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}
func TestWithCountryCode(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithCountryCode(CountryCodeUS)(req)
expected := "us"
actual := req.URL.Query().Get("country_code")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}
func TestWithDeviceTypeMobile(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithDeviceType(DeviceTypeMobile)(req)
expected := "mobile"
actual := req.URL.Query().Get("device_type")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}
func TestWithAutoParse(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithAutoParse()(req)
expected := "true"
actual := req.URL.Query().Get("autoparse")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}
func TestWithPremium(t *testing.T) {
req, _ := http.NewRequest("GET", "https://google.com", nil)
req = WithPremium()(req)
expected := "true"
actual := req.URL.Query().Get("premium")
if actual != expected {
t.Errorf("expected %s, got %v", expected, actual)
}
}