1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 02:30:56 +00:00
Beego/testing/client.go

46 lines
981 B
Go
Raw Normal View History

2013-08-21 14:47:58 +00:00
package testing
import (
2013-11-06 08:51:33 +00:00
"github.com/astaxie/beego/config"
2013-08-22 06:27:23 +00:00
"github.com/astaxie/beego/httplib"
2013-08-21 14:47:58 +00:00
)
var port = ""
var baseUrl = "http://localhost:"
2013-11-06 08:12:10 +00:00
type TestHttpRequest struct {
2013-08-21 14:47:58 +00:00
httplib.BeegoHttpRequest
}
2013-11-06 08:12:10 +00:00
func getPort() string {
if port == "" {
2013-11-06 08:51:33 +00:00
config, err := config.NewConfig("ini", "../conf/app.conf")
2013-11-06 08:12:10 +00:00
if err != nil {
2013-08-21 14:47:58 +00:00
return "8080"
}
2013-11-06 08:12:10 +00:00
port = config.String("httpport")
2013-08-21 14:47:58 +00:00
return port
}
return port
}
func Get(path string) *TestHttpRequest {
2013-11-06 08:12:10 +00:00
return &TestHttpRequest{*httplib.Get(baseUrl + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
func Post(path string) *TestHttpRequest {
2013-11-06 08:12:10 +00:00
return &TestHttpRequest{*httplib.Post(baseUrl + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
func Put(path string) *TestHttpRequest {
2013-11-06 08:12:10 +00:00
return &TestHttpRequest{*httplib.Put(baseUrl + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
func Delete(path string) *TestHttpRequest {
2013-11-06 08:12:10 +00:00
return &TestHttpRequest{*httplib.Delete(baseUrl + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
func Head(path string) *TestHttpRequest {
2013-11-06 08:12:10 +00:00
return &TestHttpRequest{*httplib.Head(baseUrl + getPort() + path)}
2013-08-21 14:47:58 +00:00
}