Reduce usage of db.DefaultContext
(#27073)
Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@ -23,7 +23,7 @@ func TestTeam_AddMember(t *testing.T) {
|
||||
|
||||
test := func(teamID, userID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, AddTeamMember(team, userID))
|
||||
assert.NoError(t, AddTeamMember(db.DefaultContext, team, userID))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: userID, TeamID: teamID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@ -37,7 +37,7 @@ func TestTeam_RemoveMember(t *testing.T) {
|
||||
|
||||
testSuccess := func(teamID, userID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, RemoveTeamMember(team, userID))
|
||||
assert.NoError(t, RemoveTeamMember(db.DefaultContext, team, userID))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: userID, TeamID: teamID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID})
|
||||
}
|
||||
@ -47,7 +47,7 @@ func TestTeam_RemoveMember(t *testing.T) {
|
||||
testSuccess(3, unittest.NonexistentID)
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1})
|
||||
err := RemoveTeamMember(team, 2)
|
||||
err := RemoveTeamMember(db.DefaultContext, team, 2)
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ func TestNewTeam(t *testing.T) {
|
||||
|
||||
const teamName = "newTeamName"
|
||||
team := &organization.Team{Name: teamName, OrgID: 3}
|
||||
assert.NoError(t, NewTeam(team))
|
||||
assert.NoError(t, NewTeam(db.DefaultContext, team))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: teamName})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@ -75,7 +75,7 @@ func TestUpdateTeam(t *testing.T) {
|
||||
team.Name = "newName"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
team.AccessMode = perm.AccessModeAdmin
|
||||
assert.NoError(t, UpdateTeam(team, true, false))
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, true, false))
|
||||
|
||||
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
|
||||
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
|
||||
@ -94,7 +94,7 @@ func TestUpdateTeam2(t *testing.T) {
|
||||
team.LowerName = "owners"
|
||||
team.Name = "Owners"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
err := UpdateTeam(team, true, false)
|
||||
err := UpdateTeam(db.DefaultContext, team, true, false)
|
||||
assert.True(t, organization.IsErrTeamAlreadyExist(err))
|
||||
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
|
||||
@ -104,7 +104,7 @@ func TestDeleteTeam(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2})
|
||||
assert.NoError(t, DeleteTeam(team))
|
||||
assert.NoError(t, DeleteTeam(db.DefaultContext, team))
|
||||
unittest.AssertNotExistsBean(t, &organization.Team{ID: team.ID})
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: team.ID})
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{TeamID: team.ID})
|
||||
@ -122,7 +122,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
|
||||
test := func(teamID, userID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, AddTeamMember(team, userID))
|
||||
assert.NoError(t, AddTeamMember(db.DefaultContext, team, userID))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: userID, TeamID: teamID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@ -136,7 +136,7 @@ func TestRemoveTeamMember(t *testing.T) {
|
||||
|
||||
testSuccess := func(teamID, userID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, RemoveTeamMember(team, userID))
|
||||
assert.NoError(t, RemoveTeamMember(db.DefaultContext, team, userID))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: userID, TeamID: teamID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID})
|
||||
}
|
||||
@ -146,7 +146,7 @@ func TestRemoveTeamMember(t *testing.T) {
|
||||
testSuccess(3, unittest.NonexistentID)
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1})
|
||||
err := RemoveTeamMember(team, 2)
|
||||
err := RemoveTeamMember(db.DefaultContext, team, 2)
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ func TestRepository_RecalculateAccesses3(t *testing.T) {
|
||||
|
||||
// adding user29 to team5 should add an explicit access row for repo 23
|
||||
// even though repo 23 is public
|
||||
assert.NoError(t, AddTeamMember(team5, user29.ID))
|
||||
assert.NoError(t, AddTeamMember(db.DefaultContext, team5, user29.ID))
|
||||
|
||||
has, err = db.GetEngine(db.DefaultContext).Get(&access_model.Access{UserID: 29, RepoID: 23})
|
||||
assert.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user