2017-06-13 20:42:36 -04:00
|
|
|
// 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 (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"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)
|
|
|
|
|
2017-06-17 00:49:45 -04:00
|
|
|
session := loginUser(t, owner.Name)
|
2017-06-13 20:42:36 -04:00
|
|
|
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)
|
2017-06-17 12:29:59 -04:00
|
|
|
doc := NewHTMLParser(t, resp.Body)
|
2017-06-17 00:49:45 -04:00
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
|
|
"_csrf": doc.GetCSRF(),
|
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "DefaultBranch",
|
|
|
|
})
|
2017-06-13 20:42:36 -04:00
|
|
|
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)
|
2017-06-17 12:29:59 -04:00
|
|
|
doc = NewHTMLParser(t, resp.Body)
|
2017-06-17 00:49:45 -04:00
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
|
|
"_csrf": doc.GetInputValueByName("_csrf"),
|
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "does_not_exist",
|
|
|
|
})
|
2017-06-13 20:42:36 -04:00
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
resp = session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
|
|
|
|
}
|