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

66 lines
1.8 KiB
Go
Raw Normal View History

2014-08-18 08:41:43 +00:00
// Copyright 2014 beego Author. All Rights Reserved.
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2014-07-03 15:40:21 +00:00
//
2014-08-18 08:41:43 +00:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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 = ""
2015-09-12 15:19:18 +00:00
var baseURL = "http://localhost:"
2013-08-21 14:47:58 +00:00
2015-09-12 15:19:18 +00:00
// TestHTTPRequest beego test request client
type TestHTTPRequest struct {
httplib.BeegoHTTPRequest
2013-08-21 14:47:58 +00:00
}
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
}
2015-09-12 15:19:18 +00:00
// Get returns test client in GET method
func Get(path string) *TestHTTPRequest {
return &TestHTTPRequest{*httplib.Get(baseURL + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
2015-09-12 15:19:18 +00:00
// Post returns test client in POST method
func Post(path string) *TestHTTPRequest {
return &TestHTTPRequest{*httplib.Post(baseURL + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
2015-09-12 15:19:18 +00:00
// Put returns test client in PUT method
func Put(path string) *TestHTTPRequest {
return &TestHTTPRequest{*httplib.Put(baseURL + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
2015-09-12 15:19:18 +00:00
// Delete returns test client in DELETE method
func Delete(path string) *TestHTTPRequest {
return &TestHTTPRequest{*httplib.Delete(baseURL + getPort() + path)}
2013-08-21 14:47:58 +00:00
}
2015-09-12 15:19:18 +00:00
// Head returns test client in HEAD method
func Head(path string) *TestHTTPRequest {
return &TestHTTPRequest{*httplib.Head(baseURL + getPort() + path)}
2013-08-21 14:47:58 +00:00
}