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

52 lines
1.6 KiB

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