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

repo_fork_test.go 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
  11. // Step0: check the existence of the to-fork repo
  12. req := NewRequest(t, "GET", "/user1/repo1")
  13. resp := session.MakeRequest(t, req)
  14. assert.EqualValues(t, http.StatusNotFound, resp.HeaderCode)
  15. // Step1: go to the main page of repo
  16. req = NewRequest(t, "GET", "/user2/repo1")
  17. resp = session.MakeRequest(t, req)
  18. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  19. // Step2: click the fork button
  20. htmlDoc := NewHTMLParser(t, resp.Body)
  21. link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
  22. assert.True(t, exists, "The template has changed")
  23. req = NewRequest(t, "GET", link)
  24. resp = session.MakeRequest(t, req)
  25. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  26. // Step3: fill the form of the forking
  27. htmlDoc = NewHTMLParser(t, resp.Body)
  28. link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
  29. assert.True(t, exists, "The template has changed")
  30. req = NewRequestWithValues(t, "POST", link, map[string]string{
  31. "_csrf": htmlDoc.GetCSRF(),
  32. "uid": "1",
  33. "repo_name": "repo1",
  34. })
  35. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  36. resp = session.MakeRequest(t, req)
  37. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  38. // Step4: check the existence of the forked repo
  39. req = NewRequest(t, "GET", "/user1/repo1")
  40. resp = session.MakeRequest(t, req)
  41. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  42. return resp
  43. }
  44. func TestRepoFork(t *testing.T) {
  45. prepareTestEnv(t)
  46. session := loginUser(t, "user1")
  47. testRepoFork(t, session)
  48. }