Tests refactored

This commit is contained in:
Deluan
2016-02-24 18:24:06 -05:00
parent 975327a6cb
commit 086d8e1578
5 changed files with 33 additions and 80 deletions
+23 -1
View File
@@ -1,6 +1,13 @@
package test
import "fmt"
import (
"fmt"
"github.com/astaxie/beego"
"net/http/httptest"
"net/http"
"path/filepath"
"runtime"
)
const (
testUser = "deluan"
@@ -9,8 +16,23 @@ const (
testVersion = "1.0.0"
)
func init() {
_, file, _, _ := runtime.Caller(1)
appPath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
beego.TestBeegoInit(appPath)
}
func AddParams(url string) string {
return fmt.Sprintf("%s?u=%s&p=%s&c=%s&v=%s", url, testUser, testPassword, testClient, testVersion)
}
func Get(url string, methodName string) (*http.Request, *httptest.ResponseRecorder) {
r, _ := http.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", methodName, fmt.Sprintf("\nUrl: %s\n\nCode[%d]\n%s", r.URL, w.Code, w.Body.String()))
return r, w
}