]> source.dussan.org Git - gitea.git/commitdiff
Fix "data race" in testlogger (#9159)
authorzeripath <art27@cantab.net>
Mon, 25 Nov 2019 23:21:37 +0000 (23:21 +0000)
committerLauris BH <lauris@nix.lv>
Mon, 25 Nov 2019 23:21:37 +0000 (01:21 +0200)
* Fix data race in testlogger

* Update git_helper_for_declarative_test.go

67 files changed:
integrations/api_admin_org_test.go
integrations/api_admin_test.go
integrations/api_branch_test.go
integrations/api_comment_test.go
integrations/api_fork_test.go
integrations/api_gpg_keys_test.go
integrations/api_issue_test.go
integrations/api_keys_test.go
integrations/api_pull_test.go
integrations/api_releases_test.go
integrations/api_repo_git_blobs_test.go
integrations/api_repo_git_commits_test.go
integrations/api_repo_git_hook_test.go
integrations/api_repo_git_ref_test.go
integrations/api_repo_git_tags_test.go
integrations/api_repo_git_trees_test.go
integrations/api_repo_lfs_locks_test.go
integrations/api_repo_raw_test.go
integrations/api_repo_tags_test.go
integrations/api_repo_test.go
integrations/api_repo_topic_test.go
integrations/api_team_test.go
integrations/api_team_user_test.go
integrations/api_token_test.go
integrations/api_user_heatmap_test.go
integrations/api_user_orgs_test.go
integrations/api_user_search_test.go
integrations/auth_ldap_test.go
integrations/branches_test.go
integrations/change_default_branch_test.go
integrations/cors_test.go
integrations/create_no_session_test.go
integrations/delete_user_test.go
integrations/download_test.go
integrations/empty_repo_test.go
integrations/explore_repos_test.go
integrations/git_test.go
integrations/gpg_git_test.go
integrations/integration_test.go
integrations/issue_test.go
integrations/lfs_getobject_test.go
integrations/links_test.go
integrations/migration-test/migration_test.go
integrations/nonascii_branches_test.go
integrations/oauth_test.go
integrations/org_test.go
integrations/pull_compare_test.go
integrations/pull_merge_test.go
integrations/pull_review_test.go
integrations/release_test.go
integrations/repo_branch_test.go
integrations/repo_commits_search_test.go
integrations/repo_commits_test.go
integrations/repo_fork_test.go
integrations/repo_generate_test.go
integrations/repo_migrate_test.go
integrations/repo_search_test.go
integrations/repo_test.go
integrations/setting_test.go
integrations/signin_test.go
integrations/signout_test.go
integrations/signup_test.go
integrations/testlogger.go
integrations/timetracking_test.go
integrations/user_test.go
integrations/version_test.go
integrations/xss_test.go

index 546ed861c255adff686dbaee16fa692253dc9bc5..b10f5607d300f31edd56532383e9b846707059d7 100644 (file)
@@ -69,7 +69,7 @@ func TestAPIAdminOrgCreateBadVisibility(t *testing.T) {
 }
 
 func TestAPIAdminOrgCreateNotAdmin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        nonAdminUsername := "user2"
        session := loginUser(t, nonAdminUsername)
        token := getTokenForLoggedInUser(t, session)
index 825aed9d504d0cf2a76f8b7b6783a0fe75587bf7..eda8f076c3e09e2c39287affbf00dc1ebe0a1864 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        // user1 is an admin user
        session := loginUser(t, "user1")
        keyOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
@@ -46,7 +46,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
 }
 
 func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        // user1 is an admin user
        session := loginUser(t, "user1")
 
@@ -56,7 +56,7 @@ func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
 }
 
 func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        normalUsername := "user2"
        session := loginUser(t, adminUsername)
@@ -79,7 +79,7 @@ func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) {
 }
 
 func TestAPISudoUser(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        normalUsername := "user2"
        session := loginUser(t, adminUsername)
@@ -95,7 +95,7 @@ func TestAPISudoUser(t *testing.T) {
 }
 
 func TestAPISudoUserForbidden(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        normalUsername := "user2"
 
@@ -108,7 +108,7 @@ func TestAPISudoUserForbidden(t *testing.T) {
 }
 
 func TestAPIListUsers(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        session := loginUser(t, adminUsername)
        token := getTokenForLoggedInUser(t, session)
@@ -131,13 +131,13 @@ func TestAPIListUsers(t *testing.T) {
 }
 
 func TestAPIListUsersNotLoggedIn(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", "/api/v1/admin/users")
        MakeRequest(t, req, http.StatusUnauthorized)
 }
 
 func TestAPIListUsersNonAdmin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        nonAdminUsername := "user2"
        session := loginUser(t, nonAdminUsername)
        token := getTokenForLoggedInUser(t, session)
index fddbe4e40ef903afeef19f9037d2243d82554d04..037a42deec6a374abff9ecd075d820156e6e5139 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        token := getTokenForLoggedInUser(t, session)
index 7bd364491268b1e8edcd5a51f7808e4651bcb1fa..0716c5d8593476428cb45a8b2579c464443be566 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPIListRepoComments(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
                models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
@@ -40,7 +40,7 @@ func TestAPIListRepoComments(t *testing.T) {
 }
 
 func TestAPIListIssueComments(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
                models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
@@ -61,7 +61,7 @@ func TestAPIListIssueComments(t *testing.T) {
 }
 
 func TestAPICreateComment(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        const commentBody = "Comment body"
 
        issue := models.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
@@ -84,7 +84,7 @@ func TestAPICreateComment(t *testing.T) {
 }
 
 func TestAPIEditComment(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        const newCommentBody = "This is the new comment body"
 
        comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
@@ -110,7 +110,7 @@ func TestAPIEditComment(t *testing.T) {
 }
 
 func TestAPIDeleteComment(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
                models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
index fec288d96fe26f3bb28e35ef1c17130d0b540f79..4f3b023312cce59901ed261c028e76b3d90ffa8d 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestCreateForkNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/forks", &api.CreateForkOption{})
        MakeRequest(t, req, http.StatusUnauthorized)
 }
index 0384dcb22a0beb32a8e7e75d7aa0b6172772d4e8..edae22205e70ab9d691d48c0208e9ea8d838906c 100644 (file)
@@ -18,7 +18,7 @@ import (
 type makeRequestFunc func(testing.TB, *http.Request, int) *httptest.ResponseRecorder
 
 func TestGPGKeys(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        token := getTokenForLoggedInUser(t, session)
 
index 24535057e247557c15993b77652475a2004128d1..f412f5af085da2e3097c5ecf736d0d8849f3d912 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPIListIssues(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -35,7 +35,7 @@ func TestAPIListIssues(t *testing.T) {
 }
 
 func TestAPICreateIssue(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        const body, title = "apiTestBody", "apiTestTitle"
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
index d9686a063ce4e180151c1db35fae6847b0787fcb..6979480543b2c8f778333b848db47216f1735bbf 100644 (file)
@@ -17,13 +17,13 @@ import (
 )
 
 func TestViewDeployKeysNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/keys")
        MakeRequest(t, req, http.StatusUnauthorized)
 }
 
 func TestCreateDeployKeyNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithJSON(t, "POST", "/api/v1/repos/user2/repo1/keys", api.CreateKeyOption{
                Title: "title",
                Key:   "key",
@@ -32,19 +32,19 @@ func TestCreateDeployKeyNoLogin(t *testing.T) {
 }
 
 func TestGetDeployKeyNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/keys/1")
        MakeRequest(t, req, http.StatusUnauthorized)
 }
 
 func TestDeleteDeployKeyNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "DELETE", "/api/v1/repos/user2/repo1/keys/1")
        MakeRequest(t, req, http.StatusUnauthorized)
 }
 
 func TestCreateReadOnlyDeployKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
        repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
 
@@ -70,7 +70,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
 }
 
 func TestCreateReadWriteDeployKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
        repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
 
@@ -95,7 +95,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
 }
 
 func TestCreateUserKey(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
 
        session := loginUser(t, "user1")
index ed5a55a9db04346a8ac337239754ac7ed3924c74..9e22be5755b9027ee2142df6d3012f02d749b31a 100644 (file)
@@ -19,7 +19,7 @@ import (
 )
 
 func TestAPIViewPulls(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
 
@@ -36,7 +36,7 @@ func TestAPIViewPulls(t *testing.T) {
 
 // TestAPIMergePullWIP ensures that we can't merge a WIP pull request
 func TestAPIMergePullWIP(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
        pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, models.Cond("has_merged = ?", false)).(*models.PullRequest)
@@ -59,7 +59,7 @@ func TestAPIMergePullWIP(t *testing.T) {
 }
 
 func TestAPICreatePullSuccess1(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
        // repo10 have code, pulls units.
        repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
@@ -79,7 +79,7 @@ func TestAPICreatePullSuccess1(t *testing.T) {
 }
 
 func TestAPICreatePullSuccess2(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
        owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
 
index 8025f1de5d59bb5742fe734efb1b7b8f5d473e97..9aef33d0689790fd31103fbc0cc76d33e3ca9ca1 100644 (file)
@@ -42,7 +42,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
 }
 
 func TestAPICreateAndUpdateRelease(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -93,7 +93,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
 }
 
 func TestAPICreateReleaseToDefaultBranch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -104,7 +104,7 @@ func TestAPICreateReleaseToDefaultBranch(t *testing.T) {
 }
 
 func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
index ad81299ba45ead1bddb7d611ea17604fbc18249f..675916eeaaaaed757dc56646298bfaf89d169fd4 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func TestAPIReposGitBlobs(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
        user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3
        user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
index 16db1e871c7272f02d29998b5999c3d3cd4de335..5291b8f4acb39805665363847ac6e22672bcee93 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func TestAPIReposGitCommits(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
@@ -35,7 +35,7 @@ func TestAPIReposGitCommits(t *testing.T) {
 }
 
 func TestAPIReposGitCommitList(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
@@ -55,7 +55,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
 }
 
 func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
@@ -72,7 +72,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
 }
 
 func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
index 1c6de786777a2679110e27398924059f517b8752..f7e55d92ae89983cc05799f33f8ba1b0eda0738a 100644 (file)
@@ -21,7 +21,7 @@ echo Hello, World!
 `
 
 func TestAPIListGitHooks(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -47,7 +47,7 @@ func TestAPIListGitHooks(t *testing.T) {
 }
 
 func TestAPIListGitHooksNoHooks(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -68,7 +68,7 @@ func TestAPIListGitHooksNoHooks(t *testing.T) {
 }
 
 func TestAPIListGitHooksNoAccess(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -81,7 +81,7 @@ func TestAPIListGitHooksNoAccess(t *testing.T) {
 }
 
 func TestAPIGetGitHook(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -99,7 +99,7 @@ func TestAPIGetGitHook(t *testing.T) {
 }
 
 func TestAPIGetGitHookNoAccess(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -112,7 +112,7 @@ func TestAPIGetGitHookNoAccess(t *testing.T) {
 }
 
 func TestAPIEditGitHook(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -142,7 +142,7 @@ func TestAPIEditGitHook(t *testing.T) {
 }
 
 func TestAPIEditGitHookNoAccess(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -158,7 +158,7 @@ func TestAPIEditGitHookNoAccess(t *testing.T) {
 }
 
 func TestAPIDeleteGitHook(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
@@ -181,7 +181,7 @@ func TestAPIDeleteGitHook(t *testing.T) {
 }
 
 func TestAPIDeleteGitHookNoAccess(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
index 1a7864a7c10daf2a906e5799b1b91e57159e6473..39237f59a257cd9f1cd0e8da4d704956274db816 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestAPIReposGitRefs(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
index d6ff08990a37a5cc1cb7ed4c8f86d5890ec4be8f..ef2e1ccd08592258ae4bdff6b2cb593b28323f84 100644 (file)
@@ -17,7 +17,7 @@ import (
 )
 
 func TestAPIGitTags(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        // Login as User2.
index 95da7738f244e4ca82add1b9d9203f8707dac3d0..6b4e120dec1e78be92d260ddf43d657a19eca36b 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestAPIReposGitTrees(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)               // owner of the repo1 & repo16
        user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)               // owner of the repo3
        user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)               // owner of neither repos
index 4fe92b33b5f3bb5104a1a5d048902300310e568e..69981d1c420009a2446c7be9e733b42b9f003813 100644 (file)
@@ -18,7 +18,7 @@ import (
 )
 
 func TestAPILFSLocksNotStarted(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        setting.LFS.StartServer = false
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
@@ -34,7 +34,7 @@ func TestAPILFSLocksNotStarted(t *testing.T) {
 }
 
 func TestAPILFSLocksNotLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        setting.LFS.StartServer = true
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
@@ -48,7 +48,7 @@ func TestAPILFSLocksNotLogin(t *testing.T) {
 }
 
 func TestAPILFSLocksLogged(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        setting.LFS.StartServer = true
        user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) //in org 3
        user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) //in org 3
index d8da9c831d51d3b12b8503ee14441c45bca5681c..62b734fa060a20df4ae7a9bcc1aa34dac22b662b 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestAPIReposRaw(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
index 252037bd4a570043b51faa092269c9ad60195245..9988a4830017b178ea03dc9745216a090cf7de64 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPIReposGetTags(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        // Login as User2.
        session := loginUser(t, user.Name)
index e021911afdb2dc503cc40581f95dcda81e081828..add546fb49ad24292c28110458a1c30e1299d1fd 100644 (file)
@@ -19,7 +19,7 @@ import (
 )
 
 func TestAPIUserReposNotLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
 
        req := NewRequestf(t, "GET", "/api/v1/users/%s/repos", user.Name)
@@ -37,7 +37,7 @@ func TestAPIUserReposNotLogin(t *testing.T) {
 }
 
 func TestAPISearchRepo(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        const keyword = "test"
 
        req := NewRequestf(t, "GET", "/api/v1/repos/search?q=%s", keyword)
@@ -207,7 +207,7 @@ func getRepo(t *testing.T, repoID int64) *models.Repository {
 }
 
 func TestAPIViewRepo(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1")
        resp := MakeRequest(t, req, http.StatusOK)
@@ -219,7 +219,7 @@ func TestAPIViewRepo(t *testing.T) {
 }
 
 func TestAPIOrgRepos(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
        user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
@@ -265,7 +265,7 @@ func TestAPIOrgRepos(t *testing.T) {
 }
 
 func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
        session := loginUser(t, user.Name)
        token := getTokenForLoggedInUser(t, session)
@@ -286,7 +286,7 @@ func TestAPIRepoMigrate(t *testing.T) {
                {ctxUserID: 2, userID: 6, cloneURL: "https://github.com/go-gitea/git.git", repoName: "git-bad-org", expectedStatus: http.StatusForbidden},
        }
 
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        for _, testCase := range testCases {
                user := models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
                session := loginUser(t, user.Name)
@@ -351,7 +351,7 @@ func TestAPIOrgRepoCreate(t *testing.T) {
                {ctxUserID: 28, orgName: "user6", repoName: "repo-not-creator", expectedStatus: http.StatusForbidden},
        }
 
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        for _, testCase := range testCases {
                user := models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
                session := loginUser(t, user.Name)
index 34c33d1b258ae66b74cd877bd9b17c89d247bddd..b96489ae2211d3223b463a7360d7eeee1ebc60c7 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPIRepoTopic(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of repo2
        user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of repo3
        user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // write access to repo 3
index 3a27cd48659adb9d8b278acde7e176b1bced15b0..be56e37edfebb8bd257815dc2ce9c1c0d80732b5 100644 (file)
@@ -18,7 +18,7 @@ import (
 )
 
 func TestAPITeam(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        teamUser := models.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
        team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
@@ -122,7 +122,7 @@ type TeamSearchResults struct {
 }
 
 func TestAPITeamSearch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        org := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
index f847c7894962b6b21be8ac7fec93f07301e72262..eec8634cb0340290ecf6908fca48f188f4edae64 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestAPITeamUser(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        normalUsername := "user2"
        session := loginUser(t, normalUsername)
index 76660d160f3ac3945cda80838789505c58c2cd1e..05b9af7a266f5eb26483dc73c45497465d06bfb8 100644 (file)
@@ -14,7 +14,7 @@ import (
 
 // TestAPICreateAndDeleteToken tests that token that was just created can be deleted
 func TestAPICreateAndDeleteToken(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
 
        req := NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
@@ -41,7 +41,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
 
 // TestAPIDeleteMissingToken ensures that error is thrown when token not found
 func TestAPIDeleteMissingToken(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
 
        req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", models.NonexistentID)
index 2e2636ce94d2d4fa0ff1b7233cee57854edc25d7..159d70e8679a2e27f58e5a55b18438cbe59adec7 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func TestUserHeatmap(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        normalUsername := "user2"
        session := loginUser(t, adminUsername)
index 6611a429d1f6815a38ba79cfb0ad7dafc7e959eb..849cb74c46ea5dec25a4e5e80f2cbf9b3804888d 100644 (file)
@@ -16,7 +16,7 @@ import (
 )
 
 func TestUserOrgs(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        normalUsername := "user2"
        session := loginUser(t, adminUsername)
@@ -44,7 +44,7 @@ func TestUserOrgs(t *testing.T) {
 }
 
 func TestMyOrgs(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        normalUsername := "user2"
        session := loginUser(t, normalUsername)
index b4c95db2f318a750d89ddf2683067fac24906dd0..6661862228202335bd5b45c28946ca130a81dbd1 100644 (file)
@@ -19,7 +19,7 @@ type SearchResults struct {
 }
 
 func TestAPIUserSearchLoggedIn(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        adminUsername := "user1"
        session := loginUser(t, adminUsername)
        token := getTokenForLoggedInUser(t, session)
@@ -37,7 +37,7 @@ func TestAPIUserSearchLoggedIn(t *testing.T) {
 }
 
 func TestAPIUserSearchNotLoggedIn(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        query := "user2"
        req := NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query)
        resp := MakeRequest(t, req, http.StatusOK)
index 9ea3184ae79270c9fae31d713ef49a09a0986b98..5cb2bad57d286fdcd7e986e75e7bdf4cbede4e53 100644 (file)
@@ -124,7 +124,7 @@ func TestLDAPUserSignin(t *testing.T) {
                t.Skip()
                return
        }
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        addAuthSourceLDAP(t, "")
 
        u := gitLDAPUsers[0]
@@ -145,7 +145,7 @@ func TestLDAPUserSync(t *testing.T) {
                t.Skip()
                return
        }
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        addAuthSourceLDAP(t, "")
        models.SyncExternalUsers()
 
@@ -191,7 +191,7 @@ func TestLDAPUserSigninFailed(t *testing.T) {
                t.Skip()
                return
        }
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        addAuthSourceLDAP(t, "")
 
        u := otherLDAPUsers[0]
@@ -204,7 +204,7 @@ func TestLDAPUserSSHKeySync(t *testing.T) {
                t.Skip()
                return
        }
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        addAuthSourceLDAP(t, "sshPublicKey")
        models.SyncExternalUsers()
 
index ea38821d218af0699a62b6f02df622e2acea2d28..ed6a73fdb43e93e1d8e6616d31000cde1abac3d2 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func TestViewBranches(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1/branches")
        resp := MakeRequest(t, req, http.StatusOK)
@@ -26,13 +26,13 @@ func TestViewBranches(t *testing.T) {
 }
 
 func TestDeleteBranch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        deleteBranch(t)
 }
 
 func TestUndoDeleteBranch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        deleteBranch(t)
        htmlDoc, name := branchAction(t, ".undo-button")
index dbd189cd28afdba2ca4dc4f665445f29e7b62c1c..dcd6d9b08b271b599642d528f33d6c0b746ea8f2 100644 (file)
@@ -13,7 +13,7 @@ import (
 )
 
 func TestChangeDefaultBranch(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
        owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
 
index 02b6b9dbfcaf1c9913de3de3fa5685b2664c26d1..466984c79a7561ddac44472fb3f16d4d2f79a8d5 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestCORSNotSet(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestf(t, "GET", "/api/v1/version")
        session := loginUser(t, "user2")
        resp := session.MakeRequest(t, req, http.StatusOK)
index 2d21f2500515e6c8bd832cc5220878987eed3ec4..8d5b6f2f7cb0ef4b19eff69ef2176b02f9c7949f 100644 (file)
@@ -52,7 +52,7 @@ func sessionFileExist(t *testing.T, tmpDir, sessionID string) bool {
 }
 
 func TestSessionFileCreation(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        oldSessionConfig := setting.SessionConfig.ProviderConfig
        defer func() {
@@ -86,7 +86,7 @@ func TestSessionFileCreation(t *testing.T) {
        routes.RegisterRoutes(mac)
 
        t.Run("NoSessionOnViewIssue", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
 
                req := NewRequest(t, "GET", "/user2/repo1/issues/1")
                resp := MakeRequest(t, req, http.StatusOK)
@@ -96,7 +96,7 @@ func TestSessionFileCreation(t *testing.T) {
                assert.False(t, sessionFileExist(t, tmpDir, sessionID))
        })
        t.Run("CreateSessionOnLogin", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
 
                req := NewRequest(t, "GET", "/user/login")
                resp := MakeRequest(t, req, http.StatusOK)
index 2a5ca89860f262974e33d8423db27da0ef828c7f..32032b3ddf45314cb69fa2cd9fd051ebdb9481ae 100644 (file)
@@ -25,7 +25,7 @@ func assertUserDeleted(t *testing.T, userID int64) {
 }
 
 func TestAdminDeleteUser(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user1")
 
@@ -40,7 +40,7 @@ func TestAdminDeleteUser(t *testing.T) {
 }
 
 func TestUserDeleteAccount(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user8")
        csrf := GetCSRF(t, session, "/user/settings/account")
@@ -55,7 +55,7 @@ func TestUserDeleteAccount(t *testing.T) {
 }
 
 func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        csrf := GetCSRF(t, session, "/user/settings/account")
index 3fd858887e6925e98722d3d1e10a37907c55d3b7..6bc5e5a9afdc906bd80dcef8a7b80ae6e8ebe8f4 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestDownloadByID(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
@@ -24,7 +24,7 @@ func TestDownloadByID(t *testing.T) {
 }
 
 func TestDownloadByIDMedia(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
index 2d72546e7d9d924143b289d76649ec8d520a9d17..77b8adf686f1adfc2387868a0d3e023063904877 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestEmptyRepo(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        subpaths := []string{
                "commits/master",
                "raw/foo",
index 7408f06302824ae71b508a55232707e2c4e0782d..c6f695612a82614bb8f3e607b0e0cf81cbfd4bdc 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 func TestExploreRepos(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/explore/repos")
        MakeRequest(t, req, http.StatusOK)
index c0e1d7d2841abae2a561b9e2442f68d4282d8a1c..f6137a947a6506afac6150f48e3885649f072b47 100644 (file)
@@ -43,7 +43,7 @@ func testGit(t *testing.T, u *url.URL) {
        forkedUserCtx := NewAPITestContext(t, "user4", "repo1")
 
        t.Run("HTTP", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                ensureAnonymousClone(t, u)
                httpContext := baseAPITestContext
                httpContext.Reponame = "repo-tmp-17"
@@ -77,7 +77,7 @@ func testGit(t *testing.T, u *url.URL) {
                })
        })
        t.Run("SSH", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                sshContext := baseAPITestContext
                sshContext.Reponame = "repo-tmp-18"
                keyname := "my-testing-key"
@@ -127,7 +127,7 @@ func ensureAnonymousClone(t *testing.T, u *url.URL) {
 
 func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string) {
        t.Run("Standard", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                little, big = commitAndPushTest(t, dstPath, "data-file-")
        })
        return
@@ -135,7 +135,7 @@ func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string
 
 func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS string) {
        t.Run("LFS", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                setting.CheckLFSVersion()
                if !setting.LFS.StartServer {
                        t.Skip()
@@ -168,7 +168,7 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
                littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix)
 
                t.Run("Locks", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        lockTest(t, dstPath)
                })
        })
@@ -177,9 +177,9 @@ func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS strin
 
 func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string) {
        t.Run("PushCommit", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                t.Run("Little", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        little = doCommitAndPush(t, littleSize, dstPath, prefix)
                })
                t.Run("Big", func(t *testing.T) {
@@ -187,7 +187,7 @@ func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string
                                t.Skip("Skipping test in short mode.")
                                return
                        }
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        big = doCommitAndPush(t, bigSize, dstPath, prefix)
                })
        })
@@ -196,7 +196,7 @@ func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string
 
 func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) {
        t.Run("Raw", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                username := ctx.Username
                reponame := ctx.Reponame
 
@@ -232,7 +232,7 @@ func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS s
 
 func mediaTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) {
        t.Run("Media", func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
 
                username := ctx.Username
                reponame := ctx.Reponame
@@ -331,7 +331,7 @@ func generateCommitWithNewData(size int, repoPath, email, fullName, prefix strin
 
 func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
        return func(t *testing.T) {
-               PrintCurrentTest(t)
+               defer PrintCurrentTest(t)()
                t.Run("CreateBranchProtected", doGitCreateBranch(dstPath, "protected"))
                t.Run("PushProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected"))
 
index cc06a5fdd2256f3c5ab1a61f49d4cc7732d110d7..a5a3406b8687b4ba7497b3cda0064c44d7ddd076 100644 (file)
@@ -66,7 +66,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("Unsigned-Initial", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
                        t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
@@ -90,7 +90,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("Unsigned-Initial-CRUD-ParentSigned", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
                                t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
@@ -107,7 +107,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("Unsigned-Initial-CRUD-Never", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        t.Run("CreateCRUDFile-Never", crudActionCreateFile(
                                t, testCtx, user, "parentsigned", "parentsigned-never", "unsigned-never2.txt", func(t *testing.T, response api.FileResponse) {
@@ -120,7 +120,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("Unsigned-Initial-CRUD-Always", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        t.Run("CreateCRUDFile-Always", crudActionCreateFile(
                                t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
@@ -139,7 +139,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("Unsigned-Initial-CRUD-ParentSigned", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        t.Run("CreateCRUDFile-Always-ParentSigned", crudActionCreateFile(
                                t, testCtx, user, "always", "always-parentsigned", "signed-always-parentsigned.txt", func(t *testing.T, response api.FileResponse) {
@@ -153,7 +153,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("AlwaysSign-Initial", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-always")
                        t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
                        t.Run("CheckMasterBranchSigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
@@ -169,7 +169,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("AlwaysSign-Initial-CRUD-Never", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-always")
                        t.Run("CreateCRUDFile-Never", crudActionCreateFile(
                                t, testCtx, user, "master", "never", "unsigned-never.txt", func(t *testing.T, response api.FileResponse) {
@@ -182,7 +182,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("AlwaysSign-Initial-CRUD-ParentSigned-On-Always", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-always")
                        t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
                                t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
@@ -196,7 +196,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("AlwaysSign-Initial-CRUD-Always", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-always")
                        t.Run("CreateCRUDFile-Always", crudActionCreateFile(
                                t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
@@ -212,7 +212,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("UnsignedMerging", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        var err error
                        t.Run("CreatePullRequest", func(t *testing.T) {
@@ -233,7 +233,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("BaseSignedMerging", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        var err error
                        t.Run("CreatePullRequest", func(t *testing.T) {
@@ -254,7 +254,7 @@ func TestGPGGit(t *testing.T) {
                u.Path = baseAPITestContext.GitPath()
 
                t.Run("CommitsSignedMerging", func(t *testing.T) {
-                       PrintCurrentTest(t)
+                       defer PrintCurrentTest(t)()
                        testCtx := NewAPITestContext(t, username, "initial-unsigned")
                        var err error
                        t.Run("CreatePullRequest", func(t *testing.T) {
index 8d7f47dcfbd95e67d4926caebe6f9f6e225b3993..4177493930b7a0b070d15f527b2ea3248c30248b 100644 (file)
@@ -173,19 +173,20 @@ func initIntegrationTest() {
        routers.GlobalInit()
 }
 
-func prepareTestEnv(t testing.TB, skip ...int) {
+func prepareTestEnv(t testing.TB, skip ...int) func() {
        t.Helper()
        ourSkip := 2
        if len(skip) > 0 {
                ourSkip += skip[0]
        }
-       PrintCurrentTest(t, ourSkip)
+       deferFn := PrintCurrentTest(t, ourSkip)
        assert.NoError(t, models.LoadFixtures())
        assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
        assert.NoError(t, os.RemoveAll(models.LocalCopyPath()))
 
        assert.NoError(t, com.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
                setting.RepoRootPath))
+       return deferFn
 }
 
 type TestSession struct {
index aa17c44254fc274d18264deb37391a2aa4158d48..5a4b75b7510e0c37aca381355a79f215e9116c42 100644 (file)
@@ -49,14 +49,14 @@ func assertMatch(t testing.TB, issue *models.Issue, keyword string) {
 }
 
 func TestNoLoginViewIssues(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1/issues")
        MakeRequest(t, req, http.StatusOK)
 }
 
 func TestViewIssuesSortByType(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
@@ -84,7 +84,7 @@ func TestViewIssuesSortByType(t *testing.T) {
 }
 
 func TestViewIssuesKeyword(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
 
@@ -104,7 +104,7 @@ func TestViewIssuesKeyword(t *testing.T) {
 }
 
 func TestNoLoginViewIssue(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1/issues/1")
        MakeRequest(t, req, http.StatusOK)
@@ -173,13 +173,13 @@ func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content,
 }
 
 func TestNewIssue(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testNewIssue(t, session, "user2", "repo1", "Title", "Description")
 }
 
 func TestIssueCommentClose(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        issueURL := testNewIssue(t, session, "user2", "repo1", "Title", "Description")
        testIssueAddComment(t, session, issueURL, "Test comment 1", "")
@@ -195,7 +195,7 @@ func TestIssueCommentClose(t *testing.T) {
 }
 
 func TestIssueCrossReference(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        // Issue that will be referenced
        _, issueBase := testIssueWithBean(t, "user2", 1, "Title", "Description")
index e9c1d1178fcf452d4ff729c51d1a18002c429622..15d9c52a756e0e8b542b2a26745b33c1402fbb94 100644 (file)
@@ -57,7 +57,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string
 }
 
 func doLfs(t *testing.T, content *[]byte, expectGzip bool) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        setting.CheckLFSVersion()
        if !setting.LFS.StartServer {
                t.Skip()
index 468c8a0f21d903762f23d72037bc92af608c3506..97b390ed12d409081576704259d15c6a10716850 100644 (file)
@@ -18,7 +18,7 @@ import (
 )
 
 func TestLinksNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        var links = []string{
                "/explore/repos",
@@ -44,7 +44,7 @@ func TestLinksNoLogin(t *testing.T) {
 }
 
 func TestRedirectsNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        var redirects = map[string]string{
                "/user2/repo1/commits/master":                "/user2/repo1/commits/branch/master",
@@ -144,7 +144,7 @@ func testLinksAsUser(userName string, t *testing.T) {
 }
 
 func TestLinksLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        testLinksAsUser("user2", t)
 }
index 8dc366dc3f3e30e1f205bbd801f97e83e1f8ab1a..4fe36dc021155a94a0e6e5c5cc50bc5a7da1498e 100644 (file)
@@ -29,8 +29,8 @@ import (
 
 var currentEngine *xorm.Engine
 
-func initMigrationTest(t *testing.T) {
-       integrations.PrintCurrentTest(t, 2)
+func initMigrationTest(t *testing.T) func() {
+       deferFn := integrations.PrintCurrentTest(t, 2)
        giteaRoot := base.SetupGiteaRoot()
        if giteaRoot == "" {
                integrations.Printf("Environment variable $GITEA_ROOT not set\n")
@@ -56,6 +56,7 @@ func initMigrationTest(t *testing.T) {
        setting.CheckLFSVersion()
        setting.InitDBConfig()
        setting.NewLogServices(true)
+       return deferFn
 }
 
 func availableVersions() ([]string, error) {
@@ -209,7 +210,7 @@ func wrappedMigrate(x *xorm.Engine) error {
 }
 
 func doMigrationTest(t *testing.T, version string) {
-       integrations.PrintCurrentTest(t)
+       defer integrations.PrintCurrentTest(t)()
        integrations.Printf("Performing migration test for %s version: %s\n", setting.Database.Type, version)
        if !restoreOldDB(t, version) {
                return
@@ -225,7 +226,7 @@ func doMigrationTest(t *testing.T, version string) {
 }
 
 func TestMigrations(t *testing.T) {
-       initMigrationTest(t)
+       defer initMigrationTest(t)()
 
        dialect := setting.Database.Type
        versions, err := availableVersions()
index e59a5ef8bc9bc6db48d4cf4ef2af851741397072..22d71e6ee20e16fd86e9a177186fea66b7e0529f 100644 (file)
@@ -161,7 +161,7 @@ func TestNonasciiBranches(t *testing.T) {
                },
        }
 
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        user := "user2"
        repo := "utf8"
index ed5761a86bd9d64843758649e069594a2ac0834a..1307baba891515b6e9c307477990e3793f8face6 100644 (file)
@@ -16,20 +16,20 @@ import (
 const defaultAuthorize = "/login/oauth/authorize?client_id=da7da3ba-9a13-4167-856f-3899de0b0138&redirect_uri=a&response_type=code&state=thestate"
 
 func TestNoClientID(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", "/login/oauth/authorize")
        ctx := loginUser(t, "user2")
        ctx.MakeRequest(t, req, 400)
 }
 
 func TestLoginRedirect(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", "/login/oauth/authorize")
        assert.Contains(t, MakeRequest(t, req, 302).Body.String(), "/user/login")
 }
 
 func TestShowAuthorize(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", defaultAuthorize)
        ctx := loginUser(t, "user4")
        resp := ctx.MakeRequest(t, req, 200)
@@ -40,7 +40,7 @@ func TestShowAuthorize(t *testing.T) {
 }
 
 func TestRedirectWithExistingGrant(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequest(t, "GET", defaultAuthorize)
        ctx := loginUser(t, "user1")
        resp := ctx.MakeRequest(t, req, 302)
@@ -51,7 +51,7 @@ func TestRedirectWithExistingGrant(t *testing.T) {
 }
 
 func TestAccessTokenExchange(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
                "client_id":     "da7da3ba-9a13-4167-856f-3899de0b0138",
@@ -74,7 +74,7 @@ func TestAccessTokenExchange(t *testing.T) {
 }
 
 func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
                "client_id":     "da7da3ba-9a13-4167-856f-3899de0b0138",
@@ -97,7 +97,7 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) {
 }
 
 func TestAccessTokenExchangeJSON(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithJSON(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
                "client_id":     "da7da3ba-9a13-4167-856f-3899de0b0138",
@@ -109,7 +109,7 @@ func TestAccessTokenExchangeJSON(t *testing.T) {
 }
 
 func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        // invalid client id
        req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
@@ -163,7 +163,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
 }
 
 func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
                "redirect_uri":  "a",
@@ -204,7 +204,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) {
 }
 
 func TestRefreshTokenInvalidation(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{
                "grant_type":    "authorization_code",
                "client_id":     "da7da3ba-9a13-4167-856f-3899de0b0138",
index d86c82989d4c524b395eaa82aa3250e137cfbaa3..b0212f4af7a73e4a7622fc3eeac9b4faab3e996a 100644 (file)
@@ -13,7 +13,7 @@ import (
 )
 
 func TestOrgRepos(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        var (
                users = []string{"user1", "user2"}
@@ -43,7 +43,7 @@ func TestOrgRepos(t *testing.T) {
 }
 
 func TestLimitedOrg(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        // not logged in user
        req := NewRequest(t, "GET", "/limited_org")
@@ -73,7 +73,7 @@ func TestLimitedOrg(t *testing.T) {
 }
 
 func TestPrivateOrg(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        // not logged in user
        req := NewRequest(t, "GET", "/privated_org")
index b473e03653f444103b17d64bc385adecd991bffc..1dec39a28f593048d861ab1dcc93de9285d0dd25 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestPullCompare(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        req := NewRequest(t, "GET", "/user2/repo1/pulls")
index a63e27e1494d979ba97637253b5ef7d59ce39cd6..218f0e4da66ad115398fcc1439cbfa454750e9c3 100644 (file)
@@ -105,7 +105,7 @@ func TestPullRebase(t *testing.T) {
 
 func TestPullRebaseMerge(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
 
                hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
                assert.NoError(t, err)
@@ -129,7 +129,7 @@ func TestPullRebaseMerge(t *testing.T) {
 
 func TestPullSquash(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
 
                hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number
                assert.NoError(t, err)
@@ -154,7 +154,7 @@ func TestPullSquash(t *testing.T) {
 
 func TestPullCleanUpAfterMerge(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
                session := loginUser(t, "user1")
                testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
                testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md", "Hello, World (Edited)\n")
@@ -190,7 +190,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) {
 
 func TestCantMergeWorkInProgress(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
                session := loginUser(t, "user1")
                testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
                testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
@@ -212,7 +212,7 @@ func TestCantMergeWorkInProgress(t *testing.T) {
 
 func TestCantMergeConflict(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
                session := loginUser(t, "user1")
                testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
                testEditFileToNewBranch(t, session, "user1", "repo1", "master", "conflict", "README.md", "Hello, World (Edited Once)\n")
@@ -258,7 +258,7 @@ func TestCantMergeConflict(t *testing.T) {
 
 func TestCantMergeUnrelated(t *testing.T) {
        onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
                session := loginUser(t, "user1")
                testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
                testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base", "README.md", "Hello, World (Edited Twice)\n")
index b4ddc0e7419a7af1f0daa4c2baa1308d39142620..d8f7b52d5499d27631e591350ec198a21c698488 100644 (file)
@@ -9,7 +9,7 @@ import (
 )
 
 func TestPullView_ReviewerMissed(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user1")
 
        req := NewRequest(t, "GET", "/pulls")
index 135607153eb90d2ae62cf002a4752fc38d84867d..855642490188d5fc0b003eff6b8842391dac5f7d 100644 (file)
@@ -58,7 +58,7 @@ func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, ver
 }
 
 func TestViewReleases(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        req := NewRequest(t, "GET", "/user2/repo1/releases")
@@ -66,14 +66,14 @@ func TestViewReleases(t *testing.T) {
 }
 
 func TestViewReleasesNoLogin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1/releases")
        MakeRequest(t, req, http.StatusOK)
 }
 
 func TestCreateRelease(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
@@ -82,7 +82,7 @@ func TestCreateRelease(t *testing.T) {
 }
 
 func TestCreateReleasePreRelease(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
@@ -91,7 +91,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
 }
 
 func TestCreateReleaseDraft(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
@@ -100,7 +100,7 @@ func TestCreateReleaseDraft(t *testing.T) {
 }
 
 func TestCreateReleasePaging(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        // Create enaugh releases to have paging
index dbde2769938bfaf424b69dab60bf4a1b84b6cbda..68806f347bd3ce777ab4d061ad0dc950b76c2f3c 100644 (file)
@@ -110,7 +110,7 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
                },
        }
        for _, test := range tests {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
                session := loginUser(t, "user2")
                if test.CreateRelease != "" {
                        createNewRelease(t, session, "/user2/repo1", test.CreateRelease, test.CreateRelease, false, false)
@@ -129,7 +129,7 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
 }
 
 func TestCreateBranchInvalidCSRF(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        req := NewRequestWithValues(t, "POST", "user2/repo1/branches/_new/branch/master", map[string]string{
                "_csrf":           "fake_csrf",
index c8bc1b56e65c0fdc765057b1d6b7262ecec82878..3cd548e810290672c27099885afb86b318a9cd13 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 func testRepoCommitsSearch(t *testing.T, query, commit string) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
index 7a4761adc64c23c9ed8535684168a80af7ac77bf..2aa0260a1690325a91f6b292a214b0af7fa304ea 100644 (file)
@@ -18,7 +18,7 @@ import (
 )
 
 func TestRepoCommits(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
@@ -33,7 +33,7 @@ func TestRepoCommits(t *testing.T) {
 }
 
 func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        token := getTokenForLoggedInUser(t, session)
index 64bc46f7771c1093e5f26d0216f2ff5ba3c9a3b4..d0542c1a72c19c8387bc5aade9dd9d560a82ce74 100644 (file)
@@ -54,13 +54,13 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO
 }
 
 func TestRepoFork(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user1")
        testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
 }
 
 func TestRepoForkToOrg(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testRepoFork(t, session, "user2", "repo1", "user3", "repo1")
 
index b8f2a45e1e3fde0e3df701d680fe323b47511503..1aa91236ea351ae1ffdd0252d1441154454ef068 100644 (file)
@@ -55,13 +55,13 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, tem
 }
 
 func TestRepoGenerate(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user1")
        testRepoGenerate(t, session, "user27", "template1", "user1", "generated1")
 }
 
 func TestRepoGenerateToOrg(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testRepoGenerate(t, session, "user27", "template1", "user2", "generated2")
 }
index 41791c1d0b47fb86e3f1545e06091407802b7a9d..f95218a114c3dd77535b6cfcabd33d6c900e4c41 100644 (file)
@@ -36,7 +36,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
 }
 
 func TestRepoMigrate(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testRepoMigrate(t, session, "https://github.com/go-gitea/git.git", "git")
 }
index 32a872e409ff6ec3d9efe04e1b4da48ed1ee9de5..eb843525fb8d0c6ea811d85c35eae56e3e35b21c 100644 (file)
@@ -29,7 +29,7 @@ func resultFilenames(t testing.TB, doc *HTMLDoc) []string {
 }
 
 func TestSearchRepo(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        repo, err := models.GetRepositoryByOwnerAndName("user2", "repo1")
        assert.NoError(t, err)
index b733c9679fc9b882a8d83a6c397492d458fdb063..b5ff072ea4cb98f87848213eda0793e5f3e72352 100644 (file)
@@ -17,7 +17,7 @@ import (
 )
 
 func TestViewRepo(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1")
        MakeRequest(t, req, http.StatusOK)
@@ -30,7 +30,7 @@ func TestViewRepo(t *testing.T) {
 }
 
 func TestViewRepo2(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user3/repo3")
        session := loginUser(t, "user2")
@@ -38,7 +38,7 @@ func TestViewRepo2(t *testing.T) {
 }
 
 func TestViewRepo3(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user3/repo3")
        session := loginUser(t, "user4")
@@ -46,7 +46,7 @@ func TestViewRepo3(t *testing.T) {
 }
 
 func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2/repo1")
        resp := MakeRequest(t, req, http.StatusOK)
@@ -60,7 +60,7 @@ func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
 }
 
 func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
@@ -78,7 +78,7 @@ func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
 }
 
 func TestViewRepoWithSymlinks(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
@@ -106,7 +106,7 @@ func TestViewAsRepoAdmin(t *testing.T) {
                "user2": true,
                "user4": false,
        } {
-               prepareTestEnv(t)
+               defer prepareTestEnv(t)()
 
                session := loginUser(t, user)
 
index 54f4fded661e053e9636b38e88b82d5eda105478..518a3b7c6f8f52e940c4be011a1d49fcad7b6784 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 func TestSettingShowUserEmailExplore(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        showUserEmail := setting.UI.ShowUserEmail
        setting.UI.ShowUserEmail = true
@@ -42,7 +42,7 @@ func TestSettingShowUserEmailExplore(t *testing.T) {
 }
 
 func TestSettingShowUserEmailProfile(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        showUserEmail := setting.UI.ShowUserEmail
        setting.UI.ShowUserEmail = true
@@ -81,7 +81,7 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
 }
 
 func TestSettingLandingPage(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        landingPage := setting.LandingPageURL
 
index 4a2bb8857ac8526a8baccecf34817ce8bdfb9aa4..390bf6408bfb2725568dde20165d96f02ab3c128 100644 (file)
@@ -31,7 +31,7 @@ func testLoginFailed(t *testing.T, username, password, message string) {
 }
 
 func TestSignin(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
 
index 002cb42daada78e57887206ac200fbbb917c986c..65957b244e6367b135476b97e5c71fe871176b53 100644 (file)
@@ -10,7 +10,7 @@ import (
 )
 
 func TestSignOut(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
 
index e122efa39c5b2bd003401c40022efb5f5d84af7d..02262ec85372ee7d18701c104db4c711f1e66cc3 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 func TestSignup(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        setting.Service.EnableCaptcha = false
 
index 91b94ac9f3ca57e4a09729741f7e0b6f5eb22abc..624abf3f811a1f16dd0341a9761dbb5649eded30 100644 (file)
@@ -27,20 +27,23 @@ var writerCloser = &testLoggerWriterCloser{}
 
 type testLoggerWriterCloser struct {
        sync.RWMutex
-       t testing.TB
+       t []*testing.TB
 }
 
 func (w *testLoggerWriterCloser) setT(t *testing.TB) {
        w.Lock()
-       w.t = *t
+       w.t = append(w.t, t)
        w.Unlock()
 }
 
 func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
        w.RLock()
-       t := w.t
+       var t *testing.TB
+       if len(w.t) > 0 {
+               t = w.t[len(w.t)-1]
+       }
        w.RUnlock()
-       if t != nil {
+       if t != nil && *t != nil {
                if len(p) > 0 && p[len(p)-1] == '\n' {
                        p = p[:len(p)-1]
                }
@@ -65,18 +68,23 @@ func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
                        }
                }()
 
-               t.Log(string(p))
+               (*t).Log(string(p))
                return len(p), nil
        }
        return len(p), nil
 }
 
 func (w *testLoggerWriterCloser) Close() error {
+       w.Lock()
+       if len(w.t) > 0 {
+               w.t = w.t[:len(w.t)-1]
+       }
+       w.Unlock()
        return nil
 }
 
 // PrintCurrentTest prints the current test to os.Stdout
-func PrintCurrentTest(t testing.TB, skip ...int) {
+func PrintCurrentTest(t testing.TB, skip ...int) func() {
        actualSkip := 1
        if len(skip) > 0 {
                actualSkip = skip[0]
@@ -89,6 +97,9 @@ func PrintCurrentTest(t testing.TB, skip ...int) {
                fmt.Fprintf(os.Stdout, "=== %s (%s:%d)\n", t.Name(), strings.TrimPrefix(filename, prefix), line)
        }
        writerCloser.setT(&t)
+       return func() {
+               _ = writerCloser.Close()
+       }
 }
 
 // Printf takes a format and args and prints the string to os.Stdout
index 890f12b300dcf27e0a674d2a16716747c05d562a..cd3002e1acc329e1b500792f9da22d384cd075a7 100644 (file)
@@ -16,20 +16,20 @@ import (
 )
 
 func TestViewTimetrackingControls(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testViewTimetrackingControls(t, session, "user2", "repo1", "1", true)
        //user2/repo1
 }
 
 func TestNotViewTimetrackingControls(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user5")
        testViewTimetrackingControls(t, session, "user2", "repo1", "1", false)
        //user2/repo1
 }
 func TestViewTimetrackingControlsDisabled(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        session := loginUser(t, "user2")
        testViewTimetrackingControls(t, session, "user3", "repo3", "1", false)
 }
index 452ea2ddf0d94fa8cfbc1cafb1d973da3b4072f5..999a182bfd3cb5be2170e9ecd8ef5146b8af5cec 100644 (file)
@@ -16,14 +16,14 @@ import (
 )
 
 func TestViewUser(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        req := NewRequest(t, "GET", "/user2")
        MakeRequest(t, req, http.StatusOK)
 }
 
 func TestRenameUsername(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        session := loginUser(t, "user2")
        req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{
@@ -39,7 +39,7 @@ func TestRenameUsername(t *testing.T) {
 }
 
 func TestRenameInvalidUsername(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        invalidUsernames := []string{
                "%2f*",
@@ -71,7 +71,7 @@ func TestRenameInvalidUsername(t *testing.T) {
 }
 
 func TestRenameReservedUsername(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        reservedUsernames := []string{
                "admin",
@@ -117,7 +117,7 @@ func TestRenameReservedUsername(t *testing.T) {
 }
 
 func TestExportUserGPGKeys(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        //Export empty key list
        testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
 
index e63ae7aee250f3a2f1dfe6003b38d47a06289e13..a1d2f6c882c303e23082e359118b271d8fc01387 100644 (file)
@@ -15,7 +15,7 @@ import (
 )
 
 func TestVersion(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
 
        setting.AppVer = "test-version-1"
        req := NewRequest(t, "GET", "/api/v1/version")
index d93d0ec036abc3c5b2f844234cf7a80ee6dbaa4f..425165dccc845626eff40e40c837ee3f1a5dcd61 100644 (file)
@@ -14,7 +14,7 @@ import (
 )
 
 func TestXSSUserFullName(t *testing.T) {
-       prepareTestEnv(t)
+       defer prepareTestEnv(t)()
        user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
        const fullName = `name & <script class="evil">alert('Oh no!');</script>`