code.gitea.io/gitea@v1.21.7/tests/integration/change_default_branch_test.go (about)

     1  // Copyright 2017 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"fmt"
     8  	"net/http"
     9  	"testing"
    10  
    11  	repo_model "code.gitea.io/gitea/models/repo"
    12  	"code.gitea.io/gitea/models/unittest"
    13  	user_model "code.gitea.io/gitea/models/user"
    14  	"code.gitea.io/gitea/tests"
    15  )
    16  
    17  func TestChangeDefaultBranch(t *testing.T) {
    18  	defer tests.PrepareTestEnv(t)()
    19  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
    20  	owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
    21  
    22  	session := loginUser(t, owner.Name)
    23  	branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
    24  
    25  	csrf := GetCSRF(t, session, branchesURL)
    26  	req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
    27  		"_csrf":  csrf,
    28  		"action": "default_branch",
    29  		"branch": "DefaultBranch",
    30  	})
    31  	session.MakeRequest(t, req, http.StatusSeeOther)
    32  
    33  	csrf = GetCSRF(t, session, branchesURL)
    34  	req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
    35  		"_csrf":  csrf,
    36  		"action": "default_branch",
    37  		"branch": "does_not_exist",
    38  	})
    39  	session.MakeRequest(t, req, http.StatusNotFound)
    40  }