1
0
Fork 0
forked from forgejo/forgejo

Refactor tests (#26464)

1. Give the global variable clear names
2. Use generic parameter for `onGiteaRun`
This commit is contained in:
wxiaoguang 2023-08-13 00:30:16 +08:00 committed by GitHub
parent bcccf4c0d6
commit c28e29fd94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 65 additions and 127 deletions

View file

@ -110,14 +110,14 @@ func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCo
}
func BenchmarkAPICreateFileSmall(b *testing.B) {
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // owner of the repo1 & repo16
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) // public repo
onGiteaRun(b, func(b *testing.B, u *url.URL) {
user2 := unittest.AssertExistsAndLoadBean(b, &user_model.User{ID: 2}) // owner of the repo1 & repo16
repo1 := unittest.AssertExistsAndLoadBean(b, &repo_model.Repository{ID: 1}) // public repo
b.ResetTimer()
for n := 0; n < b.N; n++ {
treePath := fmt.Sprintf("update/file%d.txt", n)
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
_, _ = createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
}
})
}
@ -125,16 +125,15 @@ func BenchmarkAPICreateFileSmall(b *testing.B) {
func BenchmarkAPICreateFileMedium(b *testing.B) {
data := make([]byte, 10*1024*1024)
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) // owner of the repo1 & repo16
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) // public repo
onGiteaRun(b, func(b *testing.B, u *url.URL) {
user2 := unittest.AssertExistsAndLoadBean(b, &user_model.User{ID: 2}) // owner of the repo1 & repo16
repo1 := unittest.AssertExistsAndLoadBean(b, &repo_model.Repository{ID: 1}) // public repo
b.ResetTimer()
for n := 0; n < b.N; n++ {
treePath := fmt.Sprintf("update/file%d.txt", n)
copy(data, treePath)
createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
_, _ = createFileInBranch(user2, repo1, treePath, repo1.DefaultBranch, treePath)
}
})
}