}
func TestAPIAdminOrgCreateNotAdmin(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
nonAdminUsername := "user2"
session := loginUser(t, nonAdminUsername)
token := getTokenForLoggedInUser(t, session)
)
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)
}
func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
// user1 is an admin user
session := loginUser(t, "user1")
}
func TestAPIAdminDeleteUnauthorizedKey(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
session := loginUser(t, adminUsername)
}
func TestAPISudoUser(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
session := loginUser(t, adminUsername)
}
func TestAPISudoUserForbidden(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
}
func TestAPIListUsers(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
session := loginUser(t, adminUsername)
token := getTokenForLoggedInUser(t, session)
}
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)
)
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
)
func TestAPIListRepoComments(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
}
func TestAPIListIssueComments(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
}
func TestAPICreateComment(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
const commentBody = "Comment body"
issue := models.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
}
func TestAPIEditComment(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
const newCommentBody = "This is the new comment body"
comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
}
func TestAPIDeleteComment(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
)
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)
}
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)
)
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)
}
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)
)
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",
}
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)
}
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)
}
func TestCreateUserKey(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
session := loginUser(t, "user1")
)
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)
// 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)
}
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)
}
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)
}
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)
}
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)
}
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)
)
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
)
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)
}
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)
}
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)
}
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)
`
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
}
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)
)
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)
)
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.
)
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
)
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)
}
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)
}
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
)
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)
)
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)
)
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)
}
func TestAPISearchRepo(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
const keyword = "test"
req := NewRequestf(t, "GET", "/api/v1/repos/search?q=%s", keyword)
}
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)
}
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)
}
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)
{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)
{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)
)
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
)
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)
}
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)
)
func TestAPITeamUser(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
normalUsername := "user2"
session := loginUser(t, normalUsername)
// 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{
// 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)
)
func TestUserHeatmap(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
session := loginUser(t, adminUsername)
)
func TestUserOrgs(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
session := loginUser(t, adminUsername)
}
func TestMyOrgs(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
normalUsername := "user2"
session := loginUser(t, normalUsername)
}
func TestAPIUserSearchLoggedIn(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
adminUsername := "user1"
session := loginUser(t, adminUsername)
token := getTokenForLoggedInUser(t, session)
}
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)
t.Skip()
return
}
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
addAuthSourceLDAP(t, "")
u := gitLDAPUsers[0]
t.Skip()
return
}
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
addAuthSourceLDAP(t, "")
models.SyncExternalUsers()
t.Skip()
return
}
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
addAuthSourceLDAP(t, "")
u := otherLDAPUsers[0]
t.Skip()
return
}
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
addAuthSourceLDAP(t, "sshPublicKey")
models.SyncExternalUsers()
)
func TestViewBranches(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user2/repo1/branches")
resp := MakeRequest(t, req, http.StatusOK)
}
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")
)
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)
)
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)
}
func TestSessionFileCreation(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
oldSessionConfig := setting.SessionConfig.ProviderConfig
defer func() {
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)
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)
}
func TestAdminDeleteUser(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user1")
}
func TestUserDeleteAccount(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user8")
csrf := GetCSRF(t, session, "/user/settings/account")
}
func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
csrf := GetCSRF(t, session, "/user/settings/account")
)
func TestDownloadByID(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
}
func TestDownloadByIDMedia(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
)
func TestEmptyRepo(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
subpaths := []string{
"commits/master",
"raw/foo",
)
func TestExploreRepos(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/explore/repos")
MakeRequest(t, req, http.StatusOK)
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"
})
})
t.Run("SSH", func(t *testing.T) {
- PrintCurrentTest(t)
+ defer PrintCurrentTest(t)()
sshContext := baseAPITestContext
sshContext.Reponame = "repo-tmp-18"
keyname := "my-testing-key"
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
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()
littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix)
t.Run("Locks", func(t *testing.T) {
- PrintCurrentTest(t)
+ defer PrintCurrentTest(t)()
lockTest(t, dstPath)
})
})
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) {
t.Skip("Skipping test in short mode.")
return
}
- PrintCurrentTest(t)
+ defer PrintCurrentTest(t)()
big = doCommitAndPush(t, bigSize, dstPath, prefix)
})
})
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
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
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"))
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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 {
}
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)
}
func TestViewIssuesKeyword(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
}
func TestNoLoginViewIssue(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user2/repo1/issues/1")
MakeRequest(t, req, http.StatusOK)
}
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", "")
}
func TestIssueCrossReference(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
// Issue that will be referenced
_, issueBase := testIssueWithBean(t, "user2", 1, "Title", "Description")
}
func doLfs(t *testing.T, content *[]byte, expectGzip bool) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
setting.CheckLFSVersion()
if !setting.LFS.StartServer {
t.Skip()
)
func TestLinksNoLogin(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
var links = []string{
"/explore/repos",
}
func TestRedirectsNoLogin(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
var redirects = map[string]string{
"/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
}
func TestLinksLogin(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
testLinksAsUser("user2", t)
}
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")
setting.CheckLFSVersion()
setting.InitDBConfig()
setting.NewLogServices(true)
+ return deferFn
}
func availableVersions() ([]string, 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
}
func TestMigrations(t *testing.T) {
- initMigrationTest(t)
+ defer initMigrationTest(t)()
dialect := setting.Database.Type
versions, err := availableVersions()
},
}
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
user := "user2"
repo := "utf8"
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)
}
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)
}
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",
}
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",
}
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",
}
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",
}
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",
}
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",
)
func TestOrgRepos(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
var (
users = []string{"user1", "user2"}
}
func TestLimitedOrg(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
// not logged in user
req := NewRequest(t, "GET", "/limited_org")
}
func TestPrivateOrg(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
// not logged in user
req := NewRequest(t, "GET", "/privated_org")
)
func TestPullCompare(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/pulls")
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)
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)
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")
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")
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")
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")
)
func TestPullView_ReviewerMissed(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user1")
req := NewRequest(t, "GET", "/pulls")
}
func TestViewReleases(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/releases")
}
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)
}
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)
}
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)
}
func TestCreateReleasePaging(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
// Create enaugh releases to have paging
},
}
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)
}
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",
)
func testRepoCommitsSearch(t *testing.T, query, commit string) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
)
func TestRepoCommits(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
}
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
}
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")
}
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")
}
}
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")
}
}
func TestSearchRepo(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
repo, err := models.GetRepositoryByOwnerAndName("user2", "repo1")
assert.NoError(t, err)
)
func TestViewRepo(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user2/repo1")
MakeRequest(t, req, http.StatusOK)
}
func TestViewRepo2(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user3/repo3")
session := loginUser(t, "user2")
}
func TestViewRepo3(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user3/repo3")
session := loginUser(t, "user4")
}
func TestViewRepo1CloneLinkAnonymous(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
req := NewRequest(t, "GET", "/user2/repo1")
resp := MakeRequest(t, req, http.StatusOK)
}
func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
}
func TestViewRepoWithSymlinks(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
"user2": true,
"user4": false,
} {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, user)
)
func TestSettingShowUserEmailExplore(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
showUserEmail := setting.UI.ShowUserEmail
setting.UI.ShowUserEmail = true
}
func TestSettingShowUserEmailProfile(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
showUserEmail := setting.UI.ShowUserEmail
setting.UI.ShowUserEmail = true
}
func TestSettingLandingPage(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
landingPage := setting.LandingPageURL
}
func TestSignin(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
)
func TestSignOut(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
session := loginUser(t, "user2")
)
func TestSignup(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
setting.Service.EnableCaptcha = false
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]
}
}
}()
- 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]
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
)
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)
}
)
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{
}
func TestRenameInvalidUsername(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
invalidUsernames := []string{
"%2f*",
}
func TestRenameReservedUsername(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
reservedUsernames := []string{
"admin",
}
func TestExportUserGPGKeys(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
//Export empty key list
testExportUserGPGKeys(t, "user1", `-----BEGIN PGP PUBLIC KEY BLOCK-----
)
func TestVersion(t *testing.T) {
- prepareTestEnv(t)
+ defer prepareTestEnv(t)()
setting.AppVer = "test-version-1"
req := NewRequest(t, "GET", "/api/v1/version")
)
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>`