Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

repo_fork_test.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }