Files
Atay-Makhzan/tests/integration/change_default_branch_test.go
T

41 lines
1.1 KiB
Go
Raw Normal View History

2017-06-13 20:42:36 -04:00
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2017-06-13 20:42:36 -04:00
2022-09-02 15:18:23 -04:00
package integration
2017-06-13 20:42:36 -04:00
import (
"fmt"
"net/http"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
2022-09-02 15:18:23 -04:00
"code.gitea.io/gitea/tests"
2017-06-13 20:42:36 -04:00
)
func TestChangeDefaultBranch(t *testing.T) {
2022-09-02 15:18:23 -04:00
defer tests.PrepareTestEnv(t)()
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
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,
"action": "default_branch",
"branch": "DefaultBranch",
})
session.MakeRequest(t, req, http.StatusSeeOther)
2017-07-07 15:36:47 -04:00
csrf = GetCSRF(t, session, branchesURL)
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
2017-07-07 15:36:47 -04:00
"_csrf": csrf,
"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
}