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

repo_migrate_test.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. "net/http/httptest"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName string) *httptest.ResponseRecorder {
  12. req := NewRequest(t, "GET", "/repo/migrate")
  13. resp := session.MakeRequest(t, req, http.StatusOK)
  14. htmlDoc := NewHTMLParser(t, resp.Body)
  15. link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
  16. assert.True(t, exists, "The template has changed")
  17. uid, exists := htmlDoc.doc.Find("#uid").Attr("value")
  18. assert.True(t, exists, "The template has changed")
  19. req = NewRequestWithValues(t, "POST", link, map[string]string{
  20. "_csrf": htmlDoc.GetCSRF(),
  21. "clone_addr": cloneAddr,
  22. "uid": uid,
  23. "repo_name": repoName,
  24. },
  25. )
  26. resp = session.MakeRequest(t, req, http.StatusFound)
  27. return resp
  28. }
  29. func TestRepoMigrate(t *testing.T) {
  30. prepareTestEnv(t)
  31. session := loginUser(t, "user2")
  32. testRepoMigrate(t, session, "https://github.com/go-gitea/git.git", "git")
  33. }
  34. func BenchmarkRepoMigrate(b *testing.B) {
  35. samples := []struct {
  36. url string
  37. name string
  38. }{
  39. {url: "https://github.com/go-gitea/gitea.git", name: "gitea"},
  40. {url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"},
  41. {url: "https://github.com/moby/moby.git", name: "moby"},
  42. {url: "https://github.com/golang/go.git", name: "go"},
  43. {url: "https://github.com/torvalds/linux.git", name: "linux"},
  44. }
  45. prepareTestEnv(b)
  46. session := loginUser(b, "user2")
  47. b.ResetTimer()
  48. for _, s := range samples {
  49. b.Run(s.name, func(b *testing.B) {
  50. for i := 0; i < b.N; i++ {
  51. testRepoMigrate(b, session, s.url, s.name)
  52. }
  53. })
  54. }
  55. }