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_migrate_test.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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)
  13. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  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. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  27. resp = session.MakeRequest(t, req)
  28. assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
  29. return resp
  30. }
  31. func TestRepoMigrate(t *testing.T) {
  32. prepareTestEnv(t)
  33. session := loginUser(t, "user2")
  34. testRepoMigrate(t, session, "https://github.com/go-gitea/git.git", "git")
  35. }
  36. func BenchmarkRepoMigrate(b *testing.B) {
  37. samples := []struct {
  38. url string
  39. name string
  40. }{
  41. {url: "https://github.com/go-gitea/gitea.git", name: "gitea"},
  42. {url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"},
  43. {url: "https://github.com/moby/moby.git", name: "moby"},
  44. {url: "https://github.com/golang/go.git", name: "go"},
  45. {url: "https://github.com/torvalds/linux.git", name: "linux"},
  46. }
  47. prepareTestEnv(b)
  48. session := loginUser(b, "user2")
  49. b.ResetTimer()
  50. for _, s := range samples {
  51. b.Run(s.name, func(b *testing.B) {
  52. for i := 0; i < b.N; i++ {
  53. testRepoMigrate(b, session, s.url, s.name)
  54. }
  55. })
  56. }
  57. }