Skip to content

Commit c5babc2

Browse files
committed
Add a straightforward benchmark
1 parent 8179ef8 commit c5babc2

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

integrations/editor_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
8989

9090
}
9191

92-
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath string) *TestResponse {
93-
94-
newContent := "Hello, World (Edited)\n"
92+
func testEditFile(t testing.TB, session *TestSession, user, repo, branch, filePath, newContent string) *TestResponse {
9593

9694
// Get to the 'edit this file' page
9795
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
@@ -121,9 +119,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
121119
return resp
122120
}
123121

124-
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath string) *TestResponse {
125-
126-
newContent := "Hello, World (Edited)\n"
122+
func testEditFileToNewBranch(t testing.TB, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) *TestResponse {
127123

128124
// Get to the 'edit this file' page
129125
req := NewRequest(t, "GET", path.Join(user, repo, "_edit", branch, filePath))
@@ -157,11 +153,11 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
157153
func TestEditFile(t *testing.T) {
158154
prepareTestEnv(t)
159155
session := loginUser(t, "user2")
160-
testEditFile(t, session, "user2", "repo1", "master", "README.md")
156+
testEditFile(t, session, "user2", "repo1", "master", "README.md", "Hello, World (Edited)\n")
161157
}
162158

163159
func TestEditFileToNewBranch(t *testing.T) {
164160
prepareTestEnv(t)
165161
session := loginUser(t, "user2")
166-
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "feature/test", "README.md")
162+
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "feature/test", "README.md", "Hello, World (Edited)\n")
167163
}

integrations/pull_create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
)
1515

16-
func testPullCreate(t *testing.T, session *TestSession, user, repo, branch string) *TestResponse {
16+
func testPullCreate(t testing.TB, session *TestSession, user, repo, branch string) *TestResponse {
1717
req := NewRequest(t, "GET", path.Join(user, repo))
1818
resp := session.MakeRequest(t, req, http.StatusOK)
1919

@@ -47,6 +47,6 @@ func TestPullCreate(t *testing.T) {
4747
prepareTestEnv(t)
4848
session := loginUser(t, "user1")
4949
testRepoFork(t, session)
50-
testEditFile(t, session, "user1", "repo1", "master", "README.md")
50+
testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
5151
testPullCreate(t, session, "user1", "repo1", "master")
5252
}

integrations/pull_merge_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package integrations
66

77
import (
8+
"fmt"
89
"net/http"
910
"path"
1011
"strings"
@@ -13,7 +14,7 @@ import (
1314
"github.com/stretchr/testify/assert"
1415
)
1516

16-
func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum string) *TestResponse {
17+
func testPullMerge(t testing.TB, session *TestSession, user, repo, pullnum string) *TestResponse {
1718
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullnum))
1819
resp := session.MakeRequest(t, req, http.StatusOK)
1920

@@ -49,7 +50,7 @@ func TestPullMerge(t *testing.T) {
4950
prepareTestEnv(t)
5051
session := loginUser(t, "user1")
5152
testRepoFork(t, session)
52-
testEditFile(t, session, "user1", "repo1", "master", "README.md")
53+
testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
5354

5455
resp := testPullCreate(t, session, "user1", "repo1", "master")
5556

@@ -62,7 +63,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
6263
prepareTestEnv(t)
6364
session := loginUser(t, "user1")
6465
testRepoFork(t, session)
65-
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
66+
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md", "Hello, World (Edited)\n")
6667

6768
resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
6869

@@ -91,3 +92,20 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
9192

9293
assert.EqualValues(t, "user1/feature/test has been deleted.", resultMsg)
9394
}
95+
96+
func BenchmarkPullMerge(b *testing.B) {
97+
prepareTestEnv(b)
98+
session := loginUser(b, "user1")
99+
testRepoFork(b, session)
100+
101+
for i := 0; i < b.N; i++ {
102+
content := fmt.Sprintf("Hello, World (Edited) #%d\n", i)
103+
testEditFile(b, session, "user1", "repo1", "master", "README.md", content)
104+
105+
resp := testPullCreate(b, session, "user1", "repo1", "master")
106+
107+
elem := strings.Split(RedirectURL(b, resp), "/")
108+
assert.EqualValues(b, "pulls", elem[3])
109+
testPullMerge(b, session, elem[1], elem[2], elem[4])
110+
}
111+
}

integrations/repo_fork_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
14+
func testRepoFork(t testing.TB, session *TestSession) *TestResponse {
1515
// Step0: check the existence of the to-fork repo
1616
req := NewRequest(t, "GET", "/user1/repo1")
1717
resp := session.MakeRequest(t, req, http.StatusNotFound)

0 commit comments

Comments
 (0)