2021-10-08 20:03:04 +03:00
// 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.
package integrations
import (
"net/http"
"testing"
2021-12-10 04:27:50 +03:00
repo_model "code.gitea.io/gitea/models/repo"
2021-11-16 11:53:21 +03:00
"code.gitea.io/gitea/models/unittest"
2021-11-17 15:34:35 +03:00
2021-10-08 20:03:04 +03:00
"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 )
2022-03-23 07:54:07 +03:00
session . MakeRequest ( t , req , http . StatusSeeOther )
2021-10-08 20:03:04 +03:00
// 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 )
2022-03-23 07:54:07 +03:00
resp = session . MakeRequest ( t , req , http . StatusSeeOther )
2021-10-08 20:03:04 +03:00
location := resp . HeaderMap . Get ( "Location" )
assert . Equal ( t , "/user2/repo1/src/branch/main/README.md" , location )
// check db
2021-12-10 04:27:50 +03:00
repo1 := unittest . AssertExistsAndLoadBean ( t , & repo_model . Repository { ID : 1 } ) . ( * repo_model . Repository )
2021-10-08 20:03:04 +03:00
assert . Equal ( t , "main" , repo1 . DefaultBranch )
}