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"
|
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 03:53:21 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 04:49:20 -05:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2017-06-13 20:42:36 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestChangeDefaultBranch(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2022-08-15 22:22:25 -04:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
2017-06-13 20:42:36 -04:00
|
|
|
|
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)
|
|
|
|
|
2017-07-07 15:36:47 -04:00
|
|
|
csrf := GetCSRF(t, session, branchesURL)
|
|
|
|
req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
|
|
"_csrf": csrf,
|
2017-06-17 00:49:45 -04:00
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "DefaultBranch",
|
|
|
|
})
|
2022-03-23 00:54:07 -04:00
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-06-17 00:49:45 -04:00
|
|
|
|
2017-07-07 15:36:47 -04:00
|
|
|
csrf = GetCSRF(t, session, branchesURL)
|
2017-06-17 00:49:45 -04:00
|
|
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
2017-07-07 15:36:47 -04:00
|
|
|
"_csrf": csrf,
|
2017-06-17 00:49:45 -04:00
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "does_not_exist",
|
|
|
|
})
|
2017-07-07 15:36:47 -04:00
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
2017-06-13 20:42:36 -04:00
|
|
|
}
|