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

@ -57,12 +57,10 @@ func createSSHUrl(gitPath string, u *url.URL) *url.URL {
return &u2
}
func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...bool) {
if len(prepare) == 0 || prepare[0] {
defer tests.PrepareTestEnv(t, 1)()
}
func onGiteaRun[T testing.TB](t T, callback func(T, *url.URL)) {
defer tests.PrepareTestEnv(t, 1)()
s := http.Server{
Handler: c,
Handler: testWebRoutes,
}
u, err := url.Parse(setting.AppURL)
@ -89,12 +87,6 @@ func onGiteaRunTB(t testing.TB, callback func(testing.TB, *url.URL), prepare ...
callback(t, u)
}
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL), prepare ...bool) {
onGiteaRunTB(t, func(t testing.TB, u *url.URL) {
callback(t.(*testing.T), u)
}, prepare...)
}
func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
assert.NoError(t, git.CloneWithArgs(context.Background(), git.AllowLFSFiltersArgs(), u.String(), dstLocalPath, git.CloneRepoOptions{}))