forked from neucn/neugo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
59 lines (54 loc) · 1.39 KB
/
helper_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
package neugo
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"regexp"
"testing"
)
func TestHelperMatch(t *testing.T) {
a := assert.New(t)
type matchTestCase struct {
Re *regexp.Regexp
Content string
ExpectLen int
}
singleTestCases := []*matchTestCase{
{Re: regexp.MustCompile(`([a-z])`), Content: "9", ExpectLen: 0},
{Re: regexp.MustCompile(`([a-z])`), Content: "az", ExpectLen: 1},
{Re: regexp.MustCompile(`([a-z]+)`), Content: "az", ExpectLen: 2},
}
for _, c := range singleTestCases {
result := matchSingle(c.Re, c.Content)
a.Equal(c.ExpectLen, len(result))
}
multipleTestCases := []*matchTestCase{
{Re: regexp.MustCompile(`([a-z])`), Content: "9", ExpectLen: 0},
{Re: regexp.MustCompile(`([a-z])`), Content: "az", ExpectLen: 2},
{Re: regexp.MustCompile(`([a-z]+)`), Content: "az", ExpectLen: 1},
}
for _, c := range multipleTestCases {
result := matchMultiple(c.Re, c.Content)
a.Equal(c.ExpectLen, len(result))
}
}
func TestHelperCookie(t *testing.T) {
a := assert.New(t)
client := NewSession()
cookie := &http.Cookie{
Name: "test",
Value: "yes",
Path: "/",
Domain: "neu.test",
}
setCookie(client, cookie)
u := &url.URL{
Scheme: "https",
Host: "neu.test",
Path: "/",
}
c := getCookie(client.Jar.Cookies(u), "whatever")
a.Empty(c)
c = getCookie(client.Jar.Cookies(u), cookie.Name)
a.Equal(cookie.Value, c)
}