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.

repo_fork_test.go 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. resp = session.MakeRequest(t, req)
  36. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  37. // Step4: check the existence of the forked repo
  38. req = NewRequest(t, "GET", "/user1/repo1")
  39. resp = session.MakeRequest(t, req)
  40. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  41. return resp
  42. }
  43. func TestRepoFork(t *testing.T) {
  44. prepareTestEnv(t)
  45. session := loginUser(t, "user1")
  46. testRepoFork(t, session)
  47. }