代码拉取完成,页面将自动刷新
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)
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。