-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils_test.go
More file actions
68 lines (60 loc) · 1.75 KB
/
utils_test.go
File metadata and controls
68 lines (60 loc) · 1.75 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
package tegenaria
import (
"reflect"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestGetParserByName(t *testing.T) {
server := NewTestServer()
spider := &TestSpider{NewBaseSpider("spiderParser", []string{"http://127.0.0.1" + "/testGET"})}
request := NewRequest(server.URL+"/testGET", GET, testParser)
ctx := NewContext(request, spider)
ch := make(chan *Context, 1)
f := GetParserByName(spider, "Parser")
// f(ctx, ch)
args := make([]reflect.Value, 2)
args[0] = reflect.ValueOf(ctx)
args[1] = reflect.ValueOf(ch)
f.Call(args)
item := <-ctx.Items
it := item.Item.(*testItem)
if it.test != "test" {
t.Error("call parser func fail")
}
close(ch)
}
func TestGetMachineIP(t *testing.T) {
convey.Convey("test get machine IP", t, func() {
ip, err := GetMachineIP()
convey.So(err, convey.ShouldBeNil)
convey.So(ip, convey.ShouldNotContainSubstring, "127.0.0.1")
})
}
func TestInterface2Uint(t *testing.T) {
convey.Convey("test Interface2Uint", t, func() {
v1 := Interface2Uint("2")
v2 := Interface2Uint(2)
v3 := Interface2Uint(2.0)
v4 := Interface2Uint(uint64(2))
v5 := Interface2Uint(int(2))
v6 := Interface2Uint(nil)
v7 := func() {
Interface2Uint(false)
}
v8 := Interface2Uint(uint64(2))
v9 := Interface2Uint(uint(2))
v10 := Interface2Uint(int(2))
v11 := Interface2Uint(int32(2))
convey.So(v1, convey.ShouldEqual, 2)
convey.So(v2, convey.ShouldEqual, 2)
convey.So(v3, convey.ShouldEqual, 2)
convey.So(v4, convey.ShouldEqual, 2)
convey.So(v5, convey.ShouldEqual, 2)
convey.So(v6, convey.ShouldEqual, 0)
convey.So(v8, convey.ShouldEqual, 2)
convey.So(v9, convey.ShouldEqual, 2)
convey.So(v10, convey.ShouldEqual, 2)
convey.So(v11, convey.ShouldEqual, 2)
convey.So(v7, convey.ShouldPanic)
})
}