You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rename_branch_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2021 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. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/models/unittest"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestRenameBranch(t *testing.T) {
  13. // get branch setting page
  14. session := loginUser(t, "user2")
  15. req := NewRequest(t, "GET", "/user2/repo1/settings/branches")
  16. resp := session.MakeRequest(t, req, http.StatusOK)
  17. htmlDoc := NewHTMLParser(t, resp.Body)
  18. postData := map[string]string{
  19. "_csrf": htmlDoc.GetCSRF(),
  20. "from": "master",
  21. "to": "main",
  22. }
  23. req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData)
  24. session.MakeRequest(t, req, http.StatusFound)
  25. // check new branch link
  26. req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData)
  27. session.MakeRequest(t, req, http.StatusOK)
  28. // check old branch link
  29. req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData)
  30. resp = session.MakeRequest(t, req, http.StatusFound)
  31. location := resp.HeaderMap.Get("Location")
  32. assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location)
  33. // check db
  34. repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  35. assert.Equal(t, "main", repo1.DefaultBranch)
  36. }