Use testing benchmark interface (#1993)

release/v1.15
Antoine GIRARD 2017-06-17 17:01:03 +02:00 committed by Lunny Xiao
parent d7570895cc
commit 6233e88f7f
2 changed files with 9 additions and 9 deletions

View File

@ -16,7 +16,7 @@ type HtmlDoc struct {
doc *goquery.Document doc *goquery.Document
} }
func NewHtmlParser(t *testing.T, content []byte) *HtmlDoc { func NewHtmlParser(t testing.TB, content []byte) *HtmlDoc {
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content)) doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
assert.NoError(t, err) assert.NoError(t, err)
return &HtmlDoc{doc: doc} return &HtmlDoc{doc: doc}

View File

@ -116,7 +116,7 @@ func initIntegrationTest() {
routers.GlobalInit() routers.GlobalInit()
} }
func prepareTestEnv(t *testing.T) { func prepareTestEnv(t testing.TB) {
assert.NoError(t, models.LoadFixtures()) assert.NoError(t, models.LoadFixtures())
assert.NoError(t, os.RemoveAll("integrations/gitea-integration")) assert.NoError(t, os.RemoveAll("integrations/gitea-integration"))
assert.NoError(t, com.CopyDir("integrations/gitea-integration-meta", "integrations/gitea-integration")) assert.NoError(t, com.CopyDir("integrations/gitea-integration-meta", "integrations/gitea-integration"))
@ -140,7 +140,7 @@ func (s *TestSession) GetCookie(name string) *http.Cookie {
return nil return nil
} }
func (s *TestSession) MakeRequest(t *testing.T, req *http.Request) *TestResponse { func (s *TestSession) MakeRequest(t testing.TB, req *http.Request) *TestResponse {
baseURL, err := url.Parse(setting.AppURL) baseURL, err := url.Parse(setting.AppURL)
assert.NoError(t, err) assert.NoError(t, err)
for _, c := range s.jar.Cookies(baseURL) { for _, c := range s.jar.Cookies(baseURL) {
@ -158,11 +158,11 @@ func (s *TestSession) MakeRequest(t *testing.T, req *http.Request) *TestResponse
const userPassword = "password" const userPassword = "password"
func loginUser(t *testing.T, userName string) *TestSession { func loginUser(t testing.TB, userName string) *TestSession {
return loginUserWithPassword(t, userName, userPassword) return loginUserWithPassword(t, userName, userPassword)
} }
func loginUserWithPassword(t *testing.T, userName, password string) *TestSession { func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
req := NewRequest(t, "GET", "/user/login") req := NewRequest(t, "GET", "/user/login")
resp := MakeRequest(req) resp := MakeRequest(req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
@ -214,11 +214,11 @@ type TestResponse struct {
Headers http.Header Headers http.Header
} }
func NewRequest(t *testing.T, method, urlStr string) *http.Request { func NewRequest(t testing.TB, method, urlStr string) *http.Request {
return NewRequestWithBody(t, method, urlStr, nil) return NewRequestWithBody(t, method, urlStr, nil)
} }
func NewRequestWithValues(t *testing.T, method, urlStr string, values map[string]string) *http.Request { func NewRequestWithValues(t testing.TB, method, urlStr string, values map[string]string) *http.Request {
urlValues := url.Values{} urlValues := url.Values{}
for key, value := range values { for key, value := range values {
urlValues[key] = []string{value} urlValues[key] = []string{value}
@ -226,13 +226,13 @@ func NewRequestWithValues(t *testing.T, method, urlStr string, values map[string
return NewRequestWithBody(t, method, urlStr, bytes.NewBufferString(urlValues.Encode())) return NewRequestWithBody(t, method, urlStr, bytes.NewBufferString(urlValues.Encode()))
} }
func NewRequestWithJSON(t *testing.T, method, urlStr string, v interface{}) *http.Request { func NewRequestWithJSON(t testing.TB, method, urlStr string, v interface{}) *http.Request {
jsonBytes, err := json.Marshal(v) jsonBytes, err := json.Marshal(v)
assert.NoError(t, err) assert.NoError(t, err)
return NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes)) return NewRequestWithBody(t, method, urlStr, bytes.NewBuffer(jsonBytes))
} }
func NewRequestWithBody(t *testing.T, method, urlStr string, body io.Reader) *http.Request { func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *http.Request {
request, err := http.NewRequest(method, urlStr, body) request, err := http.NewRequest(method, urlStr, body)
assert.NoError(t, err) assert.NoError(t, err)
request.RequestURI = urlStr request.RequestURI = urlStr