diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-13 20:42:36 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-14 08:42:36 +0800 |
commit | 5e92b82ac632043f622117419ad04e57e9c029f3 (patch) | |
tree | d53e110f6cb8e3bf22e1ce19d240b6b241053148 /integrations/change_default_branch_test.go | |
parent | 96152c38b1eb4243350f8457eee631205c8e499a (diff) | |
download | gitea-5e92b82ac632043f622117419ad04e57e9c029f3.tar.gz gitea-5e92b82ac632043f622117419ad04e57e9c029f3.zip |
Fix uppercase default branch bug (#1965)
Diffstat (limited to 'integrations/change_default_branch_test.go')
-rw-r--r-- | integrations/change_default_branch_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/integrations/change_default_branch_test.go b/integrations/change_default_branch_test.go new file mode 100644 index 0000000000..03ece46a58 --- /dev/null +++ b/integrations/change_default_branch_test.go @@ -0,0 +1,58 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "bytes" + "fmt" + "net/http" + "net/url" + "testing" + + "code.gitea.io/gitea/models" + + "github.com/stretchr/testify/assert" +) + +func TestChangeDefaultBranch(t *testing.T) { + prepareTestEnv(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") + 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())) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + resp = session.MakeRequest(t, req) + assert.EqualValues(t, http.StatusFound, resp.HeaderCode) + + 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())) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + resp = session.MakeRequest(t, req) + assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode) +} |