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.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. "github.com/stretchr/testify/assert"
  11. )
  12. func TestChangeDefaultBranch(t *testing.T) {
  13. prepareTestEnv(t)
  14. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  15. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  16. session := loginUser(t, owner.Name)
  17. branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
  18. req := NewRequest(t, "GET", branchesURL)
  19. resp := session.MakeRequest(t, req)
  20. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  21. doc := NewHTMLParser(t, resp.Body)
  22. req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
  23. "_csrf": doc.GetCSRF(),
  24. "action": "default_branch",
  25. "branch": "DefaultBranch",
  26. })
  27. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  28. resp = session.MakeRequest(t, req)
  29. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  30. req = NewRequest(t, "GET", branchesURL)
  31. resp = session.MakeRequest(t, req)
  32. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  33. doc = NewHTMLParser(t, resp.Body)
  34. req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
  35. "_csrf": doc.GetInputValueByName("_csrf"),
  36. "action": "default_branch",
  37. "branch": "does_not_exist",
  38. })
  39. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  40. resp = session.MakeRequest(t, req)
  41. assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
  42. }