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.

repo_migrate_test.go 1.8KB

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