diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-09 20:41:36 -0400 |
---|---|---|
committer | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-06-09 19:41:36 -0500 |
commit | 61716bd8f70f55f2c5d4090c87700f6b9b6fc632 (patch) | |
tree | d3bab40ab681e0ccbbba964273ba32f6d0ace8e0 /integrations | |
parent | 6d613fb28ef5d884bbea1e2a4d8c3e21fc398ecc (diff) | |
download | gitea-61716bd8f70f55f2c5d4090c87700f6b9b6fc632.tar.gz gitea-61716bd8f70f55f2c5d4090c87700f6b9b6fc632.zip |
Display URLs in integration test logs (#1924)
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/api_repo_test.go | 6 | ||||
-rw-r--r-- | integrations/api_team_test.go | 3 | ||||
-rw-r--r-- | integrations/delete_user_test.go | 6 | ||||
-rw-r--r-- | integrations/editor_test.go | 26 | ||||
-rw-r--r-- | integrations/integration_test.go | 17 | ||||
-rw-r--r-- | integrations/internal_test.go | 3 | ||||
-rw-r--r-- | integrations/issue_test.go | 6 | ||||
-rw-r--r-- | integrations/pull_compare_test.go | 6 | ||||
-rw-r--r-- | integrations/release_test.go | 3 | ||||
-rw-r--r-- | integrations/repo_commits_test.go | 12 | ||||
-rw-r--r-- | integrations/repo_fork_test.go | 15 | ||||
-rw-r--r-- | integrations/repo_test.go | 3 | ||||
-rw-r--r-- | integrations/signup_test.go | 6 | ||||
-rw-r--r-- | integrations/user_test.go | 3 | ||||
-rw-r--r-- | integrations/version_test.go | 3 |
15 files changed, 47 insertions, 71 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go index 64649efe1d..e4f907cc91 100644 --- a/integrations/api_repo_test.go +++ b/integrations/api_repo_test.go @@ -16,8 +16,7 @@ import ( func TestAPIUserReposNotLogin(t *testing.T) { assert.NoError(t, models.LoadFixtures()) - req, err := http.NewRequest("GET", "/api/v1/users/user2/repos", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/api/v1/users/user2/repos") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } @@ -25,8 +24,7 @@ func TestAPIUserReposNotLogin(t *testing.T) { func TestAPISearchRepoNotLogin(t *testing.T) { assert.NoError(t, models.LoadFixtures()) - req, err := http.NewRequest("GET", "/api/v1/repos/search?q=Test", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go index 543e1579cd..69198cd7eb 100644 --- a/integrations/api_team_test.go +++ b/integrations/api_team_test.go @@ -25,8 +25,7 @@ func TestAPITeam(t *testing.T) { session := loginUser(t, user.Name, "password") url := fmt.Sprintf("/api/v1/teams/%d", teamUser.TeamID) - req, err := http.NewRequest("GET", url, nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", url) resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) diff --git a/integrations/delete_user_test.go b/integrations/delete_user_test.go index bf38eeae2b..2040830f2e 100644 --- a/integrations/delete_user_test.go +++ b/integrations/delete_user_test.go @@ -20,18 +20,16 @@ func TestDeleteUser(t *testing.T) { session := loginUser(t, "user1", "password") - req, err := http.NewRequest("GET", "/admin/users/8", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/admin/users/8") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) doc, err := NewHtmlParser(resp.Body) assert.NoError(t, err) - req, err = http.NewRequest("POST", "/admin/users/8/delete", + req = NewRequestBody(t, "POST", "/admin/users/8/delete", bytes.NewBufferString(url.Values{ "_csrf": []string{doc.GetInputValueByName("_csrf")}, }.Encode())) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) diff --git a/integrations/editor_test.go b/integrations/editor_test.go index 976def89eb..64212d3f29 100644 --- a/integrations/editor_test.go +++ b/integrations/editor_test.go @@ -20,8 +20,7 @@ func TestCreateFile(t *testing.T) { session := loginUser(t, "user2", "password") // Request editor page - req, err := http.NewRequest("GET", "/user2/repo1/_new/master/", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/_new/master/") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -31,7 +30,7 @@ func TestCreateFile(t *testing.T) { assert.NotEmpty(t, lastCommit) // Save new file to master branch - req, err = http.NewRequest("POST", "/user2/repo1/_new/master/", + req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", bytes.NewBufferString(url.Values{ "_csrf": []string{doc.GetInputValueByName("_csrf")}, "last_commit": []string{lastCommit}, @@ -40,7 +39,6 @@ func TestCreateFile(t *testing.T) { "commit_choice": []string{"direct"}, }.Encode()), ) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusFound, resp.HeaderCode) @@ -52,8 +50,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { session := loginUser(t, "user2", "password") // Open repository branch settings - req, err := http.NewRequest("GET", "/user2/repo1/settings/branches", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/settings/branches") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -61,7 +58,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { assert.NoError(t, err) // Change master branch to protected - req, err = http.NewRequest("POST", "/user2/repo1/settings/branches?action=protected_branch", + req = NewRequestBody(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", bytes.NewBufferString(url.Values{ "_csrf": []string{doc.GetInputValueByName("_csrf")}, "branchName": []string{"master"}, @@ -78,8 +75,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { assert.EqualValues(t, flashCookie.Value, "success%3Dmaster%2BLocked%2Bsuccessfully") // Request editor page - req, err = http.NewRequest("GET", "/user2/repo1/_new/master/", nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", "/user2/repo1/_new/master/") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -89,7 +85,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { assert.NotEmpty(t, lastCommit) // Save new file to master branch - req, err = http.NewRequest("POST", "/user2/repo1/_new/master/", + req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", bytes.NewBufferString(url.Values{ "_csrf": []string{doc.GetInputValueByName("_csrf")}, "last_commit": []string{lastCommit}, @@ -98,7 +94,6 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { "commit_choice": []string{"direct"}, }.Encode()), ) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -111,8 +106,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa newContent := "Hello, World (Edited)\n" // Get to the 'edit this file' page - req, err := http.NewRequest("GET", path.Join(user, repo, "_edit", branch, filePath), nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath)) resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -122,7 +116,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa assert.NotEmpty(t, lastCommit) // Submit the edits - req, err = http.NewRequest("POST", path.Join(user, repo, "_edit", branch, filePath), + req = NewRequestBody(t, "POST", path.Join(user, repo, "_edit", branch, filePath), bytes.NewBufferString(url.Values{ "_csrf": []string{htmlDoc.GetInputValueByName("_csrf")}, "last_commit": []string{lastCommit}, @@ -131,14 +125,12 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa "commit_choice": []string{"direct"}, }.Encode()), ) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusFound, resp.HeaderCode) // Verify the change - req, err = http.NewRequest("GET", path.Join(user, repo, "raw", branch, filePath), nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", path.Join(user, repo, "raw", branch, filePath)) resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) assert.EqualValues(t, newContent, string(resp.Body)) diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 88b4614b76..1cc1eb049f 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -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{ diff --git a/integrations/internal_test.go b/integrations/internal_test.go index 12d6fc8dc9..3af079dc81 100644 --- a/integrations/internal_test.go +++ b/integrations/internal_test.go @@ -19,11 +19,10 @@ import ( func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) { reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName)) - req, err := http.NewRequest("GET", reqURL, nil) + req := NewRequest(t, "GET", reqURL) t.Log(reqURL) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken)) - assert.NoError(t, err) resp := MakeRequest(req) if isErr { assert.EqualValues(t, 500, resp.HeaderCode) diff --git a/integrations/issue_test.go b/integrations/issue_test.go index 51fcc96f8c..3b486dc505 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -14,8 +14,7 @@ import ( func TestNoLoginViewIssues(t *testing.T) { prepareTestEnv(t) - req, err := http.NewRequest("GET", "/user2/repo1/issues", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/issues") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } @@ -23,8 +22,7 @@ func TestNoLoginViewIssues(t *testing.T) { func TestNoLoginViewIssue(t *testing.T) { prepareTestEnv(t) - req, err := http.NewRequest("GET", "/user2/repo1/issues/1", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/issues/1") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/pull_compare_test.go b/integrations/pull_compare_test.go index 567a1d13f7..737d5ab823 100644 --- a/integrations/pull_compare_test.go +++ b/integrations/pull_compare_test.go @@ -15,8 +15,7 @@ func TestPullCompare(t *testing.T) { prepareTestEnv(t) session := loginUser(t, "user2", "password") - req, err := http.NewRequest("GET", "/user2/repo1/pulls", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/pulls") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) htmlDoc, err := NewHtmlParser(resp.Body) @@ -24,8 +23,7 @@ func TestPullCompare(t *testing.T) { link, exists := htmlDoc.doc.Find(".navbar").Find(".ui.green.button").Attr("href") assert.True(t, exists, "The template has changed") - req, err = http.NewRequest("GET", link, nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", link) resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/release_test.go b/integrations/release_test.go index ec8ad360f4..8f29ddc639 100644 --- a/integrations/release_test.go +++ b/integrations/release_test.go @@ -15,8 +15,7 @@ func TestViewReleases(t *testing.T) { prepareTestEnv(t) session := loginUser(t, "user2", "password") - req, err := http.NewRequest("GET", "/user2/repo1/releases", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/releases") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/repo_commits_test.go b/integrations/repo_commits_test.go index 9be9b78e53..476458e63f 100644 --- a/integrations/repo_commits_test.go +++ b/integrations/repo_commits_test.go @@ -19,8 +19,7 @@ func TestRepoCommits(t *testing.T) { session := loginUser(t, "user2", "password") // Request repository commits page - req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/commits/master") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -37,8 +36,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { session := loginUser(t, "user2", "password") // Request repository commits page - req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1/commits/master") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -50,16 +48,14 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { assert.NotEmpty(t, commitURL) // Call API to add status for commit - req, err = http.NewRequest("POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL), + req = NewRequestBody(t, "POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL), bytes.NewBufferString("{\"state\":\""+state+"\", \"target_url\": \"http://test.ci/\", \"description\": \"\", \"context\": \"testci\"}")) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/json") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusCreated, resp.HeaderCode) - req, err = http.NewRequest("GET", "/user2/repo1/commits/master", nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", "/user2/repo1/commits/master") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) diff --git a/integrations/repo_fork_test.go b/integrations/repo_fork_test.go index 15c096b1ab..59a15d8483 100644 --- a/integrations/repo_fork_test.go +++ b/integrations/repo_fork_test.go @@ -15,14 +15,12 @@ import ( func testRepoFork(t *testing.T, session *TestSession) { // Step0: check the existence of the to-fork repo - req, err := http.NewRequest("GET", "/user1/repo1", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user1/repo1") resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode) // Step1: go to the main page of repo - req, err = http.NewRequest("GET", "/user2/repo1", nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", "/user2/repo1") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -31,8 +29,7 @@ func testRepoFork(t *testing.T, session *TestSession) { assert.NoError(t, err) link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href") assert.True(t, exists, "The template has changed") - req, err = http.NewRequest("GET", link, nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", link) resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) @@ -41,21 +38,19 @@ func testRepoFork(t *testing.T, session *TestSession) { assert.NoError(t, err) link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action") assert.True(t, exists, "The template has changed") - req, err = http.NewRequest("POST", link, + req = NewRequestBody(t, "POST", link, bytes.NewBufferString(url.Values{ "_csrf": []string{htmlDoc.GetInputValueByName("_csrf")}, "uid": []string{"1"}, "repo_name": []string{"repo1"}, }.Encode()), ) - assert.NoError(t, err) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusFound, resp.HeaderCode) // Step4: check the existence of the forked repo - req, err = http.NewRequest("GET", "/user1/repo1", nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", "/user1/repo1") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/repo_test.go b/integrations/repo_test.go index 37874c275d..130418f3fd 100644 --- a/integrations/repo_test.go +++ b/integrations/repo_test.go @@ -14,8 +14,7 @@ import ( func TestViewRepo(t *testing.T) { prepareTestEnv(t) - req, err := http.NewRequest("GET", "/user2/repo1", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2/repo1") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/signup_test.go b/integrations/signup_test.go index 49017b29ff..4bb84c1a20 100644 --- a/integrations/signup_test.go +++ b/integrations/signup_test.go @@ -20,7 +20,7 @@ func TestSignup(t *testing.T) { setting.Service.EnableCaptcha = false - req, err := http.NewRequest("POST", "/user/sign_up", + req := NewRequestBody(t, "POST", "/user/sign_up", bytes.NewBufferString(url.Values{ "user_name": []string{"exampleUser"}, "email": []string{"exampleUser@example.com"}, @@ -28,14 +28,12 @@ func TestSignup(t *testing.T) { "retype": []string{"examplePassword"}, }.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) // should be able to view new user's page - req, err = http.NewRequest("GET", "/exampleUser", nil) - assert.NoError(t, err) + req = NewRequest(t, "GET", "/exampleUser") resp = MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/user_test.go b/integrations/user_test.go index f9358c1682..d3f7ca1b53 100644 --- a/integrations/user_test.go +++ b/integrations/user_test.go @@ -14,8 +14,7 @@ import ( func TestViewUser(t *testing.T) { prepareTestEnv(t) - req, err := http.NewRequest("GET", "/user2", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/user2") resp := MakeRequest(req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) } diff --git a/integrations/version_test.go b/integrations/version_test.go index 7243357403..b5902a20a3 100644 --- a/integrations/version_test.go +++ b/integrations/version_test.go @@ -20,8 +20,7 @@ func TestVersion(t *testing.T) { prepareTestEnv(t) setting.AppVer = "1.1.0+dev" - req, err := http.NewRequest("GET", "/api/v1/version", nil) - assert.NoError(t, err) + req := NewRequest(t, "GET", "/api/v1/version") resp := MakeRequest(req) var version gitea.ServerVersion |