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