diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-17 00:49:45 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-17 12:49:45 +0800 |
commit | ce9b86082c4824917023b1bb480648d0cc56dd04 (patch) | |
tree | ba28673c955d009492557f54953857165e2f8da8 /integrations/change_default_branch_test.go | |
parent | a3868ef5367315f52334b81819a412cad820f5eb (diff) | |
download | gitea-ce9b86082c4824917023b1bb480648d0cc56dd04.tar.gz gitea-ce9b86082c4824917023b1bb480648d0cc56dd04.zip |
Consolidate boilerplate in integration tests (#1979)
Diffstat (limited to 'integrations/change_default_branch_test.go')
-rw-r--r-- | integrations/change_default_branch_test.go | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/integrations/change_default_branch_test.go b/integrations/change_default_branch_test.go index 03ece46a58..d34cd176cd 100644 --- a/integrations/change_default_branch_test.go +++ b/integrations/change_default_branch_test.go @@ -5,10 +5,8 @@ package integrations import ( - "bytes" "fmt" "net/http" - "net/url" "testing" "code.gitea.io/gitea/models" @@ -21,21 +19,19 @@ func TestChangeDefaultBranch(t *testing.T) { repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) - session := loginUser(t, owner.Name, "password") + session := loginUser(t, owner.Name) branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name) req := NewRequest(t, "GET", branchesURL) resp := session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) - doc, err := NewHtmlParser(resp.Body) - assert.NoError(t, err) - - req = NewRequestBody(t, "POST", branchesURL, - bytes.NewBufferString(url.Values{ - "_csrf": []string{doc.GetInputValueByName("_csrf")}, - "action": []string{"default_branch"}, - "branch": []string{"DefaultBranch"}, - }.Encode())) + doc := NewHtmlParser(t, resp.Body) + + req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{ + "_csrf": doc.GetCSRF(), + "action": "default_branch", + "branch": "DefaultBranch", + }) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusFound, resp.HeaderCode) @@ -43,15 +39,13 @@ func TestChangeDefaultBranch(t *testing.T) { req = NewRequest(t, "GET", branchesURL) resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusOK, resp.HeaderCode) - doc, err = NewHtmlParser(resp.Body) - assert.NoError(t, err) - - req = NewRequestBody(t, "POST", branchesURL, - bytes.NewBufferString(url.Values{ - "_csrf": []string{doc.GetInputValueByName("_csrf")}, - "action": []string{"default_branch"}, - "branch": []string{"does_not_exist"}, - }.Encode())) + doc = NewHtmlParser(t, resp.Body) + + req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{ + "_csrf": doc.GetInputValueByName("_csrf"), + "action": "default_branch", + "branch": "does_not_exist", + }) req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp = session.MakeRequest(t, req) assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode) |