|
|
|
@ -8,7 +8,6 @@ import ( |
|
|
|
|
"strings" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
|
"code.gitea.io/gitea/models/unittest" |
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
) |
|
|
|
@ -16,36 +15,36 @@ import ( |
|
|
|
|
func TestTeam_IsOwnerTeam(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
assert.True(t, team.IsOwnerTeam()) |
|
|
|
|
|
|
|
|
|
team = db.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team = unittest.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
assert.False(t, team.IsOwnerTeam()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestTeam_IsMember(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
assert.True(t, team.IsMember(2)) |
|
|
|
|
assert.False(t, team.IsMember(4)) |
|
|
|
|
assert.False(t, team.IsMember(db.NonexistentID)) |
|
|
|
|
assert.False(t, team.IsMember(unittest.NonexistentID)) |
|
|
|
|
|
|
|
|
|
team = db.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team = unittest.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
assert.True(t, team.IsMember(2)) |
|
|
|
|
assert.True(t, team.IsMember(4)) |
|
|
|
|
assert.False(t, team.IsMember(db.NonexistentID)) |
|
|
|
|
assert.False(t, team.IsMember(unittest.NonexistentID)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestTeam_GetRepositories(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, team.GetRepositories(&SearchTeamOptions{})) |
|
|
|
|
assert.Len(t, team.Repos, team.NumRepos) |
|
|
|
|
for _, repo := range team.Repos { |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamRepo{TeamID: teamID, RepoID: repo.ID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamRepo{TeamID: teamID, RepoID: repo.ID}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(1) |
|
|
|
@ -56,11 +55,11 @@ func TestTeam_GetMembers(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, team.GetMembers(&SearchMembersOptions{})) |
|
|
|
|
assert.Len(t, team.Members, team.NumMembers) |
|
|
|
|
for _, member := range team.Members { |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{UID: member.ID, TeamID: teamID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: member.ID, TeamID: teamID}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(1) |
|
|
|
@ -71,10 +70,10 @@ func TestTeam_AddMember(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID, userID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, team.AddMember(userID)) |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID}) |
|
|
|
|
} |
|
|
|
|
test(1, 2) |
|
|
|
|
test(1, 4) |
|
|
|
@ -85,17 +84,17 @@ func TestTeam_RemoveMember(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
testSuccess := func(teamID, userID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, team.RemoveMember(userID)) |
|
|
|
|
db.AssertNotExistsBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}) |
|
|
|
|
} |
|
|
|
|
testSuccess(1, 4) |
|
|
|
|
testSuccess(2, 2) |
|
|
|
|
testSuccess(3, 2) |
|
|
|
|
testSuccess(3, db.NonexistentID) |
|
|
|
|
testSuccess(3, unittest.NonexistentID) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
err := team.RemoveMember(2) |
|
|
|
|
assert.True(t, IsErrLastOrgOwner(err)) |
|
|
|
|
} |
|
|
|
@ -104,13 +103,13 @@ func TestTeam_HasRepository(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID, repoID int64, expected bool) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.Equal(t, expected, team.HasRepository(repoID)) |
|
|
|
|
} |
|
|
|
|
test(1, 1, false) |
|
|
|
|
test(1, 3, true) |
|
|
|
|
test(1, 5, true) |
|
|
|
|
test(1, db.NonexistentID, false) |
|
|
|
|
test(1, unittest.NonexistentID, false) |
|
|
|
|
|
|
|
|
|
test(2, 3, true) |
|
|
|
|
test(2, 5, false) |
|
|
|
@ -120,33 +119,33 @@ func TestTeam_AddRepository(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
testSuccess := func(teamID, repoID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository) |
|
|
|
|
assert.NoError(t, team.AddRepository(repo)) |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamRepo{TeamID: teamID, RepoID: repoID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}, &Repository{ID: repoID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamRepo{TeamID: teamID, RepoID: repoID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &Repository{ID: repoID}) |
|
|
|
|
} |
|
|
|
|
testSuccess(2, 3) |
|
|
|
|
testSuccess(2, 5) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) |
|
|
|
|
assert.Error(t, team.AddRepository(repo)) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: 1}, &Repository{ID: 1}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: 1}, &Repository{ID: 1}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestTeam_RemoveRepository(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
testSuccess := func(teamID, repoID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, team.RemoveRepository(repoID)) |
|
|
|
|
db.AssertNotExistsBean(t, &TeamRepo{TeamID: teamID, RepoID: repoID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}, &Repository{ID: repoID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &TeamRepo{TeamID: teamID, RepoID: repoID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &Repository{ID: repoID}) |
|
|
|
|
} |
|
|
|
|
testSuccess(2, 3) |
|
|
|
|
testSuccess(2, 5) |
|
|
|
|
testSuccess(1, db.NonexistentID) |
|
|
|
|
testSuccess(1, unittest.NonexistentID) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestIsUsableTeamName(t *testing.T) { |
|
|
|
@ -160,8 +159,8 @@ func TestNewTeam(t *testing.T) { |
|
|
|
|
const teamName = "newTeamName" |
|
|
|
|
team := &Team{Name: teamName, OrgID: 3} |
|
|
|
|
assert.NoError(t, NewTeam(team)) |
|
|
|
|
db.AssertExistsAndLoadBean(t, &Team{Name: teamName}) |
|
|
|
|
CheckConsistencyFor(t, &Team{}, &User{ID: team.OrgID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &Team{Name: teamName}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{}, &User{ID: team.OrgID}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetTeam(t *testing.T) { |
|
|
|
@ -178,7 +177,7 @@ func TestGetTeam(t *testing.T) { |
|
|
|
|
|
|
|
|
|
_, err := GetTeam(3, "nonexistent") |
|
|
|
|
assert.Error(t, err) |
|
|
|
|
_, err = GetTeam(db.NonexistentID, "Owners") |
|
|
|
|
_, err = GetTeam(unittest.NonexistentID, "Owners") |
|
|
|
|
assert.Error(t, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -195,7 +194,7 @@ func TestGetTeamByID(t *testing.T) { |
|
|
|
|
testSuccess(3) |
|
|
|
|
testSuccess(4) |
|
|
|
|
|
|
|
|
|
_, err := GetTeamByID(db.NonexistentID) |
|
|
|
|
_, err := GetTeamByID(unittest.NonexistentID) |
|
|
|
|
assert.Error(t, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -203,48 +202,48 @@ func TestUpdateTeam(t *testing.T) { |
|
|
|
|
// successful update
|
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team.LowerName = "newname" |
|
|
|
|
team.Name = "newName" |
|
|
|
|
team.Description = strings.Repeat("A long description!", 100) |
|
|
|
|
team.Authorize = AccessModeAdmin |
|
|
|
|
assert.NoError(t, UpdateTeam(team, true, false)) |
|
|
|
|
|
|
|
|
|
team = db.AssertExistsAndLoadBean(t, &Team{Name: "newName"}).(*Team) |
|
|
|
|
team = unittest.AssertExistsAndLoadBean(t, &Team{Name: "newName"}).(*Team) |
|
|
|
|
assert.True(t, strings.HasPrefix(team.Description, "A long description!")) |
|
|
|
|
|
|
|
|
|
access := db.AssertExistsAndLoadBean(t, &Access{UserID: 4, RepoID: 3}).(*Access) |
|
|
|
|
access := unittest.AssertExistsAndLoadBean(t, &Access{UserID: 4, RepoID: 3}).(*Access) |
|
|
|
|
assert.EqualValues(t, AccessModeAdmin, access.Mode) |
|
|
|
|
|
|
|
|
|
CheckConsistencyFor(t, &Team{ID: team.ID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: team.ID}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestUpdateTeam2(t *testing.T) { |
|
|
|
|
// update to already-existing team
|
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team.LowerName = "owners" |
|
|
|
|
team.Name = "Owners" |
|
|
|
|
team.Description = strings.Repeat("A long description!", 100) |
|
|
|
|
err := UpdateTeam(team, true, false) |
|
|
|
|
assert.True(t, IsErrTeamAlreadyExist(err)) |
|
|
|
|
|
|
|
|
|
CheckConsistencyFor(t, &Team{ID: team.ID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: team.ID}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDeleteTeam(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 2}).(*Team) |
|
|
|
|
assert.NoError(t, DeleteTeam(team)) |
|
|
|
|
db.AssertNotExistsBean(t, &Team{ID: team.ID}) |
|
|
|
|
db.AssertNotExistsBean(t, &TeamRepo{TeamID: team.ID}) |
|
|
|
|
db.AssertNotExistsBean(t, &TeamUser{TeamID: team.ID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &Team{ID: team.ID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &TeamRepo{TeamID: team.ID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &TeamUser{TeamID: team.ID}) |
|
|
|
|
|
|
|
|
|
// check that team members don't have "leftover" access to repos
|
|
|
|
|
user := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) |
|
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) |
|
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) |
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) |
|
|
|
|
accessMode, err := AccessLevel(user, repo) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.True(t, accessMode < AccessModeWrite) |
|
|
|
@ -260,25 +259,25 @@ func TestIsTeamMember(t *testing.T) { |
|
|
|
|
|
|
|
|
|
test(3, 1, 2, true) |
|
|
|
|
test(3, 1, 4, false) |
|
|
|
|
test(3, 1, db.NonexistentID, false) |
|
|
|
|
test(3, 1, unittest.NonexistentID, false) |
|
|
|
|
|
|
|
|
|
test(3, 2, 2, true) |
|
|
|
|
test(3, 2, 4, true) |
|
|
|
|
|
|
|
|
|
test(3, db.NonexistentID, db.NonexistentID, false) |
|
|
|
|
test(db.NonexistentID, db.NonexistentID, db.NonexistentID, false) |
|
|
|
|
test(3, unittest.NonexistentID, unittest.NonexistentID, false) |
|
|
|
|
test(unittest.NonexistentID, unittest.NonexistentID, unittest.NonexistentID, false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetTeamMembers(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
members, err := GetTeamMembers(teamID) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Len(t, members, team.NumMembers) |
|
|
|
|
for _, member := range members { |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{UID: member.ID, TeamID: teamID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: member.ID, TeamID: teamID}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(1) |
|
|
|
@ -291,12 +290,12 @@ func TestGetUserTeams(t *testing.T) { |
|
|
|
|
teams, _, err := SearchTeam(&SearchTeamOptions{UserID: userID}) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
for _, team := range teams { |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{TeamID: team.ID, UID: userID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{TeamID: team.ID, UID: userID}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(2) |
|
|
|
|
test(5) |
|
|
|
|
test(db.NonexistentID) |
|
|
|
|
test(unittest.NonexistentID) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestGetUserOrgTeams(t *testing.T) { |
|
|
|
@ -306,22 +305,22 @@ func TestGetUserOrgTeams(t *testing.T) { |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
for _, team := range teams { |
|
|
|
|
assert.EqualValues(t, orgID, team.OrgID) |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{TeamID: team.ID, UID: userID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{TeamID: team.ID, UID: userID}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
test(3, 2) |
|
|
|
|
test(3, 4) |
|
|
|
|
test(3, db.NonexistentID) |
|
|
|
|
test(3, unittest.NonexistentID) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAddTeamMember(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID, userID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, AddTeamMember(team, userID)) |
|
|
|
|
db.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID}) |
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}, &User{ID: team.OrgID}) |
|
|
|
|
} |
|
|
|
|
test(1, 2) |
|
|
|
|
test(1, 4) |
|
|
|
@ -332,17 +331,17 @@ func TestRemoveTeamMember(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
testSuccess := func(teamID, userID int64) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.NoError(t, RemoveTeamMember(team, userID)) |
|
|
|
|
db.AssertNotExistsBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
CheckConsistencyFor(t, &Team{ID: teamID}) |
|
|
|
|
unittest.AssertNotExistsBean(t, &TeamUser{UID: userID, TeamID: teamID}) |
|
|
|
|
unittest.CheckConsistencyFor(t, &Team{ID: teamID}) |
|
|
|
|
} |
|
|
|
|
testSuccess(1, 4) |
|
|
|
|
testSuccess(2, 2) |
|
|
|
|
testSuccess(3, 2) |
|
|
|
|
testSuccess(3, db.NonexistentID) |
|
|
|
|
testSuccess(3, unittest.NonexistentID) |
|
|
|
|
|
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: 1}).(*Team) |
|
|
|
|
err := RemoveTeamMember(team, 2) |
|
|
|
|
assert.True(t, IsErrLastOrgOwner(err)) |
|
|
|
|
} |
|
|
|
@ -351,13 +350,13 @@ func TestHasTeamRepo(t *testing.T) { |
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase()) |
|
|
|
|
|
|
|
|
|
test := func(teamID, repoID int64, expected bool) { |
|
|
|
|
team := db.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
team := unittest.AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
|
|
|
|
assert.Equal(t, expected, HasTeamRepo(team.OrgID, teamID, repoID)) |
|
|
|
|
} |
|
|
|
|
test(1, 1, false) |
|
|
|
|
test(1, 3, true) |
|
|
|
|
test(1, 5, true) |
|
|
|
|
test(1, db.NonexistentID, false) |
|
|
|
|
test(1, unittest.NonexistentID, false) |
|
|
|
|
|
|
|
|
|
test(2, 3, true) |
|
|
|
|
test(2, 5, false) |
|
|
|
|