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

pull_merge_test.go 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. "net/http"
  7. "path"
  8. "strings"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
  13. req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
  14. resp := session.MakeRequest(t, req, http.StatusOK)
  15. // Click the little green button to create a pull
  16. htmlDoc := NewHTMLParser(t, resp.Body)
  17. link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
  18. assert.True(t, exists, "The template has changed")
  19. req = NewRequestWithValues(t, "POST", link, map[string]string{
  20. "_csrf": htmlDoc.GetCSRF(),
  21. })
  22. resp = session.MakeRequest(t, req, http.StatusFound)
  23. return resp
  24. }
  25. func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
  26. req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
  27. resp := session.MakeRequest(t, req, http.StatusOK)
  28. // Click the little green button to create a pull
  29. htmlDoc := NewHTMLParser(t, resp.Body)
  30. link, exists := htmlDoc.doc.Find(".comments .merge .delete-button").Attr("data-url")
  31. assert.True(t, exists, "The template has changed")
  32. req = NewRequestWithValues(t, "POST", link, map[string]string{
  33. "_csrf": htmlDoc.GetCSRF(),
  34. })
  35. resp = session.MakeRequest(t, req, http.StatusOK)
  36. return resp
  37. }
  38. func TestPullMerge(t *testing.T) {
  39. prepareTestEnv(t)
  40. session := loginUser(t, "user1")
  41. testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
  42. testEditFile(t, session, "user1", "repo1", "master", "README.md")
  43. resp := testPullCreate(t, session, "user1", "repo1", "master")
  44. elem := strings.Split(RedirectURL(t, resp), "/")
  45. assert.EqualValues(t, "pulls", elem[3])
  46. testPullMerge(t, session, elem[1], elem[2], elem[4])
  47. }
  48. func TestPullCleanUpAfterMerge(t *testing.T) {
  49. prepareTestEnv(t)
  50. session := loginUser(t, "user1")
  51. testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
  52. testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
  53. resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
  54. elem := strings.Split(RedirectURL(t, resp), "/")
  55. assert.EqualValues(t, "pulls", elem[3])
  56. testPullMerge(t, session, elem[1], elem[2], elem[4])
  57. // Check PR branch deletion
  58. resp = testPullCleanUp(t, session, elem[1], elem[2], elem[4])
  59. respJSON := struct {
  60. Redirect string
  61. }{}
  62. DecodeJSON(t, resp, &respJSON)
  63. assert.NotEmpty(t, respJSON.Redirect, "Redirected URL is not found")
  64. elem = strings.Split(respJSON.Redirect, "/")
  65. assert.EqualValues(t, "pulls", elem[3])
  66. // Check branch deletion result
  67. req := NewRequest(t, "GET", respJSON.Redirect)
  68. resp = session.MakeRequest(t, req, http.StatusOK)
  69. htmlDoc := NewHTMLParser(t, resp.Body)
  70. resultMsg := htmlDoc.doc.Find(".ui.message>p").Text()
  71. assert.EqualValues(t, "user1/feature/test has been deleted.", resultMsg)
  72. }