1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-16 17:40:54 +00:00
Beego/testing/client.go

61 lines
1.5 KiB
Go
Raw Normal View History

2014-04-12 05:18:18 +00:00
// Beego (http://beego.me/)
2014-07-03 15:40:21 +00:00
//
2014-04-12 05:18:18 +00:00
// @description beego is an open-source, high-performance web framework for the Go programming language.
2014-07-03 15:40:21 +00:00
//
2014-04-12 05:18:18 +00:00
// @link http://github.com/astaxie/beego for the canonical source repository
2014-07-03 15:40:21 +00:00
//
2014-04-12 05:18:18 +00:00
// @license http://github.com/astaxie/beego/blob/master/LICENSE
2014-07-03 15:40:21 +00:00
//
2014-04-12 05:18:18 +00:00
// @authors astaxie
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:"
// beego test request client
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
}
// returns test client in GET method
2013-08-21 14:47:58 +00:00
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
}
// returns test client in POST method
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
}
// returns test client in PUT method
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
}
// returns test client in DELETE method
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
}
// returns test client in HEAD method
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
}