2016-02-25 00:06:49 +01:00
|
|
|
package test
|
|
|
|
|
2016-02-25 00:24:06 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/astaxie/beego"
|
2016-02-25 02:21:51 +01:00
|
|
|
"net/http"
|
2016-02-26 00:52:07 +01:00
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
2016-02-25 00:24:06 +01:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
)
|
2016-02-25 00:06:49 +01:00
|
|
|
|
|
|
|
const (
|
2016-02-26 00:52:07 +01:00
|
|
|
testUser = "deluan"
|
2016-02-25 00:06:49 +01:00
|
|
|
testPassword = "wordpass"
|
2016-02-26 00:52:07 +01:00
|
|
|
testClient = "test"
|
|
|
|
testVersion = "1.0.0"
|
2016-02-25 00:06:49 +01:00
|
|
|
)
|
|
|
|
|
2016-02-25 00:24:06 +01:00
|
|
|
func init() {
|
|
|
|
_, file, _, _ := runtime.Caller(1)
|
2016-02-26 00:52:07 +01:00
|
|
|
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
|
2016-02-25 00:24:06 +01:00
|
|
|
beego.TestBeegoInit(appPath)
|
2016-02-25 17:14:16 +01:00
|
|
|
|
|
|
|
noLog := os.Getenv("NOLOG")
|
|
|
|
if noLog != "" {
|
|
|
|
beego.SetLevel(beego.LevelError)
|
|
|
|
}
|
2016-02-25 00:24:06 +01:00
|
|
|
}
|
|
|
|
|
2016-02-25 00:06:49 +01:00
|
|
|
func AddParams(url string) string {
|
|
|
|
return fmt.Sprintf("%s?u=%s&p=%s&c=%s&v=%s", url, testUser, testPassword, testClient, testVersion)
|
|
|
|
}
|
|
|
|
|
2016-02-25 00:33:13 +01:00
|
|
|
func Get(url string, testCase string) (*http.Request, *httptest.ResponseRecorder) {
|
2016-02-25 00:24:06 +01:00
|
|
|
r, _ := http.NewRequest("GET", url, nil)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
beego.BeeApp.Handlers.ServeHTTP(w, r)
|
|
|
|
|
2016-02-25 17:14:16 +01:00
|
|
|
beego.Debug("testing", testCase, fmt.Sprintf("\nUrl: %s\nStatus Code: [%d]\n%s", r.URL, w.Code, w.Body.String()))
|
2016-02-25 00:24:06 +01:00
|
|
|
|
|
|
|
return r, w
|
|
|
|
}
|