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

pull_merge_test.go 1.7 kB

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. "bytes"
  7. "net/http"
  8. "net/url"
  9. "path"
  10. "strings"
  11. "testing"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
  15. req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
  16. resp := session.MakeRequest(t, req)
  17. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  18. // Click the little green button to craete a pull
  19. htmlDoc, err := NewHtmlParser(resp.Body)
  20. assert.NoError(t, err)
  21. link, exists := htmlDoc.doc.Find("form.ui.form>button.ui.green.button").Parent().Attr("action")
  22. assert.True(t, exists, "The template has changed")
  23. req = NewRequestBody(t, "POST", link,
  24. bytes.NewBufferString(url.Values{
  25. "_csrf": []string{htmlDoc.GetInputValueByName("_csrf")},
  26. }.Encode()),
  27. )
  28. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  29. resp = session.MakeRequest(t, req)
  30. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  31. return resp
  32. }
  33. func TestPullMerge(t *testing.T) {
  34. prepareTestEnv(t)
  35. session := loginUser(t, "user1", "password")
  36. testRepoFork(t, session)
  37. testEditFile(t, session, "user1", "repo1", "master", "README.md")
  38. resp := testPullCreate(t, session, "user1", "repo1", "master")
  39. redirectedURL := resp.Headers["Location"]
  40. assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
  41. elem := strings.Split(redirectedURL[0], "/")
  42. assert.EqualValues(t, "pulls", elem[3])
  43. testPullMerge(t, session, elem[1], elem[2], elem[4])
  44. }