1 Star 0 Fork 1

wetrycode/tegenaria

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils_test.go 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
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)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/wetrycode/tegenaria.git
git@gitee.com:wetrycode/tegenaria.git
wetrycode
tegenaria
tegenaria
master

搜索帮助