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