mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 19:06:18 +01:00 
			
		
		
		
	Refactor tests (#26464)
1. Give the global variable clear names 2. Use generic parameter for `onGiteaRun`
This commit is contained in:
		| @@ -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) | ||||
| 		} | ||||
| 	}) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user