Merge pull request #168 from fanngyuan/master
添加用于测试的request,后面我会在bee工具里添加一个单元测试的例子。
Showing
1 changed file
with
45 additions
and
0 deletions
testing/client.go
0 → 100644
| 1 | package testing | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/fanngyuan/beego" | ||
| 5 | "github.com/fanngyuan/beego/httplib" | ||
| 6 | ) | ||
| 7 | |||
| 8 | var port = "" | ||
| 9 | var baseUrl = "http://localhost:" | ||
| 10 | |||
| 11 | type TestHttpRequest struct{ | ||
| 12 | httplib.BeegoHttpRequest | ||
| 13 | } | ||
| 14 | |||
| 15 | func getPort() string{ | ||
| 16 | if port==""{ | ||
| 17 | config,err:= beego.LoadConfig("../conf/app.conf") | ||
| 18 | if err!=nil{ | ||
| 19 | return "8080" | ||
| 20 | } | ||
| 21 | port=config.String("httpport") | ||
| 22 | return port | ||
| 23 | } | ||
| 24 | return port | ||
| 25 | } | ||
| 26 | |||
| 27 | func Get(path string) *TestHttpRequest { | ||
| 28 | return &TestHttpRequest{*httplib.Get(baseUrl+getPort()+path)} | ||
| 29 | } | ||
| 30 | |||
| 31 | func Post(path string) *TestHttpRequest { | ||
| 32 | return &TestHttpRequest{*httplib.Post(baseUrl+getPort()+path)} | ||
| 33 | } | ||
| 34 | |||
| 35 | func Put(path string) *TestHttpRequest { | ||
| 36 | return &TestHttpRequest{*httplib.Put(baseUrl+getPort()+path)} | ||
| 37 | } | ||
| 38 | |||
| 39 | func Delete(path string) *TestHttpRequest { | ||
| 40 | return &TestHttpRequest{*httplib.Delete(baseUrl+getPort()+path)} | ||
| 41 | } | ||
| 42 | |||
| 43 | func Head(path string) *TestHttpRequest { | ||
| 44 | return &TestHttpRequest{*httplib.Head(baseUrl+getPort()+path)} | ||
| 45 | } |
-
Please register or sign in to post a comment