2017-06-14 06:12:36 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-06-14 06:12:36 +05:30
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2017-06-14 06:12:36 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 14:23:21 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-09-03 00:48:23 +05:30
|
|
|
"code.gitea.io/gitea/tests"
|
2017-06-14 06:12:36 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestChangeDefaultBranch(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-08-16 07:52:25 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
2017-06-14 06:12:36 +05:30
|
|
|
|
2017-06-17 10:19:45 +05:30
|
|
|
session := loginUser(t, owner.Name)
|
2017-06-14 06:12:36 +05:30
|
|
|
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
|
|
|
|
|
2017-07-08 01:06:47 +05:30
|
|
|
csrf := GetCSRF(t, session, branchesURL)
|
|
|
|
req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
|
|
"_csrf": csrf,
|
2017-06-17 10:19:45 +05:30
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "DefaultBranch",
|
|
|
|
})
|
2022-03-23 10:24:07 +05:30
|
|
|
session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-06-17 10:19:45 +05:30
|
|
|
|
2017-07-08 01:06:47 +05:30
|
|
|
csrf = GetCSRF(t, session, branchesURL)
|
2017-06-17 10:19:45 +05:30
|
|
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
2017-07-08 01:06:47 +05:30
|
|
|
"_csrf": csrf,
|
2017-06-17 10:19:45 +05:30
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "does_not_exist",
|
|
|
|
})
|
2017-07-08 01:06:47 +05:30
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
2017-06-14 06:12:36 +05:30
|
|
|
}
|