2017-06-14 09:42:36 +09: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"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-19 20:49:59 +09:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2017-06-14 09:42:36 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestChangeDefaultBranch(t *testing.T) {
|
2019-11-26 08:21:37 +09:00
|
|
|
defer prepareTestEnv(t)()
|
2021-09-19 20:49:59 +09:00
|
|
|
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
2017-06-14 09:42:36 +09:00
|
|
|
|
2017-06-17 13:49:45 +09:00
|
|
|
session := loginUser(t, owner.Name)
|
2017-06-14 09:42:36 +09:00
|
|
|
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
|
|
|
|
|
2017-07-08 04:36:47 +09:00
|
|
|
csrf := GetCSRF(t, session, branchesURL)
|
|
|
|
req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
|
|
|
"_csrf": csrf,
|
2017-06-17 13:49:45 +09:00
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "DefaultBranch",
|
|
|
|
})
|
2017-07-08 04:36:47 +09:00
|
|
|
session.MakeRequest(t, req, http.StatusFound)
|
2017-06-17 13:49:45 +09:00
|
|
|
|
2017-07-08 04:36:47 +09:00
|
|
|
csrf = GetCSRF(t, session, branchesURL)
|
2017-06-17 13:49:45 +09:00
|
|
|
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
|
2017-07-08 04:36:47 +09:00
|
|
|
"_csrf": csrf,
|
2017-06-17 13:49:45 +09:00
|
|
|
"action": "default_branch",
|
|
|
|
"branch": "does_not_exist",
|
|
|
|
})
|
2017-07-08 04:36:47 +09:00
|
|
|
session.MakeRequest(t, req, http.StatusNotFound)
|
2017-06-14 09:42:36 +09:00
|
|
|
}
|