Skip to content

Commit 754482b

Browse files
typelesslunny
authored andcommitted
Add integration test for repository migration (#1983)
1 parent 75f166b commit 754482b

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ test-mysql: integrations.test
164164
test-pgsql: integrations.test
165165
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
166166

167+
168+
.PHONY: bench-sqlite
169+
bench-sqlite: integrations.sqlite.test
170+
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.bench .
171+
172+
.PHONY: bench-mysql
173+
bench-mysql: integrations.test
174+
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.bench .
175+
176+
.PHONY: bench-pgsql
177+
bench-pgsql: integrations.test
178+
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.bench .
179+
180+
167181
.PHONY: integration-test-coverage
168182
integration-test-coverage: integrations.cover.test
169183
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out

integrations/repo_migrate_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)