Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

change_default_branch_test.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "fmt"
  7. "net/http"
  8. "testing"
  9. "code.gitea.io/gitea/models"
  10. )
  11. func TestChangeDefaultBranch(t *testing.T) {
  12. prepareTestEnv(t)
  13. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  14. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  15. session := loginUser(t, owner.Name)
  16. branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
  17. csrf := GetCSRF(t, session, branchesURL)
  18. req := NewRequestWithValues(t, "POST", branchesURL, map[string]string{
  19. "_csrf": csrf,
  20. "action": "default_branch",
  21. "branch": "DefaultBranch",
  22. })
  23. session.MakeRequest(t, req, http.StatusFound)
  24. csrf = GetCSRF(t, session, branchesURL)
  25. req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
  26. "_csrf": csrf,
  27. "action": "default_branch",
  28. "branch": "does_not_exist",
  29. })
  30. session.MakeRequest(t, req, http.StatusNotFound)
  31. }