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

pull_merge_test.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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)
  15. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  16. // Click the little green button to craete a pull
  17. htmlDoc := NewHTMLParser(t, resp.Body)
  18. link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
  19. assert.True(t, exists, "The template has changed")
  20. req = NewRequestWithValues(t, "POST", link, map[string]string{
  21. "_csrf": htmlDoc.GetCSRF(),
  22. })
  23. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  24. resp = session.MakeRequest(t, req)
  25. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  26. return resp
  27. }
  28. func TestPullMerge(t *testing.T) {
  29. prepareTestEnv(t)
  30. session := loginUser(t, "user1")
  31. testRepoFork(t, session)
  32. testEditFile(t, session, "user1", "repo1", "master", "README.md")
  33. resp := testPullCreate(t, session, "user1", "repo1", "master")
  34. redirectedURL := resp.Headers["Location"]
  35. assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
  36. elem := strings.Split(redirectedURL[0], "/")
  37. assert.EqualValues(t, "pulls", elem[3])
  38. testPullMerge(t, session, elem[1], elem[2], elem[4])
  39. }