1
0
Fork 0
forked from forgejo/forgejo

Display URLs in integration test logs (#1924)

This commit is contained in:
Ethan Koenig 2017-06-09 20:41:36 -04:00 committed by Bo-Yi Wu
parent 6d613fb28e
commit 61716bd8f7
15 changed files with 47 additions and 71 deletions

View file

@ -147,22 +147,20 @@ func (s *TestSession) MakeRequest(t *testing.T, req *http.Request) *TestResponse
}
func loginUser(t *testing.T, userName, password string) *TestSession {
req, err := http.NewRequest("GET", "/user/login", nil)
assert.NoError(t, err)
req := NewRequest(t, "GET", "/user/login")
resp := MakeRequest(req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
doc, err := NewHtmlParser(resp.Body)
assert.NoError(t, err)
req, err = http.NewRequest("POST", "/user/login",
req = NewRequestBody(t, "POST", "/user/login",
bytes.NewBufferString(url.Values{
"_csrf": []string{doc.GetInputValueByName("_csrf")},
"user_name": []string{userName},
"password": []string{password},
}.Encode()),
)
assert.NoError(t, err)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp = MakeRequest(req)
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
@ -204,6 +202,17 @@ type TestResponse struct {
Headers http.Header
}
func NewRequest(t *testing.T, method, url string) *http.Request {
return NewRequestBody(t, method, url, nil)
}
func NewRequestBody(t *testing.T, method, url string, body io.Reader) *http.Request {
request, err := http.NewRequest(method, url, body)
assert.NoError(t, err)
request.RequestURI = url
return request
}
func MakeRequest(req *http.Request) *TestResponse {
buffer := bytes.NewBuffer(nil)
respWriter := &TestResponseWriter{