mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.4 KiB
46 lines
1.4 KiB
3 years ago
|
// Copyright 2021 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.
|
||
|
|
||
2 years ago
|
package integration
|
||
3 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
|
||
3 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestRenameBranch(t *testing.T) {
|
||
|
// get branch setting page
|
||
|
session := loginUser(t, "user2")
|
||
|
req := NewRequest(t, "GET", "/user2/repo1/settings/branches")
|
||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||
|
|
||
|
postData := map[string]string{
|
||
|
"_csrf": htmlDoc.GetCSRF(),
|
||
|
"from": "master",
|
||
|
"to": "main",
|
||
|
}
|
||
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData)
|
||
3 years ago
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
||
3 years ago
|
|
||
|
// check new branch link
|
||
|
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData)
|
||
|
session.MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
|
// check old branch link
|
||
|
req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
|
||
3 years ago
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||
3 years ago
|
location := resp.HeaderMap.Get("Location")
|
||
|
assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
|
||
|
|
||
|
// check db
|
||
2 years ago
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||
3 years ago
|
assert.Equal(t, "main", repo1.DefaultBranch)
|
||
|
}
|