forked from CuteReimu/bilibili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
60 lines (57 loc) · 1.13 KB
/
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
package bilibili
import (
"net/http"
"strings"
"testing"
)
func deepEquals(a, b []*http.Cookie) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i].Name != b[i].Name {
return false
}
if a[i].Value != b[i].Value {
return false
}
if a[i].Domain != b[i].Domain {
return false
}
if a[i].Path != b[i].Path {
return false
}
}
return true
}
func TestCookie(t *testing.T) {
{
result := []*http.Cookie{ // 不测试Expires,因为time.Time转化成string再转化回来会丢失单调时钟
{Name: "a", Value: "1", Domain: "bilibili.com", Path: "/"},
{Name: "b", Value: "2", Domain: "bilibili.com", Path: "/"},
}
s := make([]string, 0, len(result))
for _, cookie := range result {
s = append(s, cookie.String())
}
c := New()
c.SetCookiesString(strings.Join(s, "\n"))
if !deepEquals(result, c.GetCookies()) {
t.Fail()
}
}
{
result := []*http.Cookie{
{Name: "a", Value: "1"},
{Name: "b", Value: "2"},
}
c := New()
c.SetRawCookies("a=1; b=2")
if c.GetCookiesString() != "a=1\nb=2" {
t.Fail()
}
if !deepEquals(result, c.GetCookies()) {
t.Fail()
}
}
}