Better tests organization

This commit is contained in:
Deluan
2016-02-27 18:42:08 -05:00
parent ecc0df9e7c
commit ce240cfeff
8 changed files with 54 additions and 35 deletions
+30
View File
@@ -0,0 +1,30 @@
package api_test
import (
"fmt"
"github.com/astaxie/beego"
"net/http"
"net/http/httptest"
_ "github.com/deluan/gosonic/routers"
)
const (
testUser = "deluan"
testPassword = "wordpass"
testClient = "test"
testVersion = "1.0.0"
)
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, testCase string) (*http.Request, *httptest.ResponseRecorder) {
r, _ := http.NewRequest("GET", url, nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Debug("testing", testCase, fmt.Sprintf("\nUrl: %s\nStatus Code: [%d]\n%s", r.URL, w.Code, w.Body.String()))
return r, w
}