summaryrefslogtreecommitdiffstats
path: root/models/org_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 13:49:59 +0200
committerGitHub <noreply@github.com>2021-09-19 13:49:59 +0200
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/org_test.go
parent[skip ci] Updated licenses and gitignores (diff)
downloadforgejo-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.xz
forgejo-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/org_test.go')
-rw-r--r--models/org_test.go239
1 files changed, 120 insertions, 119 deletions
diff --git a/models/org_test.go b/models/org_test.go
index 7ba9d8ee88..9990a9d9f1 100644
--- a/models/org_test.go
+++ b/models/org_test.go
@@ -7,6 +7,7 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
@@ -14,7 +15,7 @@ import (
)
func TestUser_IsOwnedBy(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
for _, testCase := range []struct {
OrgID int64
UserID int64
@@ -27,7 +28,7 @@ func TestUser_IsOwnedBy(t *testing.T) {
{2, 2, false}, // user2 is not an organization
{2, 3, false},
} {
- org := AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
+ org := db.AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
isOwner, err := org.IsOwnedBy(testCase.UserID)
assert.NoError(t, err)
assert.Equal(t, testCase.ExpectedOwner, isOwner)
@@ -35,7 +36,7 @@ func TestUser_IsOwnedBy(t *testing.T) {
}
func TestUser_IsOrgMember(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
for _, testCase := range []struct {
OrgID int64
UserID int64
@@ -48,7 +49,7 @@ func TestUser_IsOrgMember(t *testing.T) {
{2, 2, false}, // user2 is not an organization
{2, 3, false},
} {
- org := AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
+ org := db.AssertExistsAndLoadBean(t, &User{ID: testCase.OrgID}).(*User)
isMember, err := org.IsOrgMember(testCase.UserID)
assert.NoError(t, err)
assert.Equal(t, testCase.ExpectedMember, isMember)
@@ -56,8 +57,8 @@ func TestUser_IsOrgMember(t *testing.T) {
}
func TestUser_GetTeam(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
team, err := org.GetTeam("team1")
assert.NoError(t, err)
assert.Equal(t, org.ID, team.OrgID)
@@ -66,26 +67,26 @@ func TestUser_GetTeam(t *testing.T) {
_, err = org.GetTeam("does not exist")
assert.True(t, IsErrTeamNotExist(err))
- nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ nonOrg := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
_, err = nonOrg.GetTeam("team")
assert.True(t, IsErrTeamNotExist(err))
}
func TestUser_GetOwnerTeam(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
team, err := org.GetOwnerTeam()
assert.NoError(t, err)
assert.Equal(t, org.ID, team.OrgID)
- nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ nonOrg := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
_, err = nonOrg.GetOwnerTeam()
assert.True(t, IsErrTeamNotExist(err))
}
func TestUser_GetTeams(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.NoError(t, org.LoadTeams())
if assert.Len(t, org.Teams, 4) {
assert.Equal(t, int64(1), org.Teams[0].ID)
@@ -96,8 +97,8 @@ func TestUser_GetTeams(t *testing.T) {
}
func TestUser_GetMembers(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.NoError(t, org.GetMembers())
if assert.Len(t, org.Members, 3) {
assert.Equal(t, int64(2), org.Members[0].ID)
@@ -107,67 +108,67 @@ func TestUser_GetMembers(t *testing.T) {
}
func TestUser_AddMember(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
// add a user that is not a member
- AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
+ db.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
prevNumMembers := org.NumMembers
assert.NoError(t, org.AddMember(5))
- AssertExistsAndLoadBean(t, &OrgUser{UID: 5, OrgID: 3})
- org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ db.AssertExistsAndLoadBean(t, &OrgUser{UID: 5, OrgID: 3})
+ org = db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.Equal(t, prevNumMembers+1, org.NumMembers)
// add a user that is already a member
- AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
+ db.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
prevNumMembers = org.NumMembers
assert.NoError(t, org.AddMember(4))
- AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
- org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ db.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
+ org = db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.Equal(t, prevNumMembers, org.NumMembers)
CheckConsistencyFor(t, &User{})
}
func TestUser_RemoveMember(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
// remove a user that is a member
- AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
+ db.AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
prevNumMembers := org.NumMembers
assert.NoError(t, org.RemoveMember(4))
- AssertNotExistsBean(t, &OrgUser{UID: 4, OrgID: 3})
- org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ db.AssertNotExistsBean(t, &OrgUser{UID: 4, OrgID: 3})
+ org = db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.Equal(t, prevNumMembers-1, org.NumMembers)
// remove a user that is not a member
- AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
+ db.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
prevNumMembers = org.NumMembers
assert.NoError(t, org.RemoveMember(5))
- AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
- org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ db.AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
+ org = db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
assert.Equal(t, prevNumMembers, org.NumMembers)
CheckConsistencyFor(t, &User{}, &Team{})
}
func TestUser_RemoveOrgRepo(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
- repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: org.ID}).(*Repository)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ repo := db.AssertExistsAndLoadBean(t, &Repository{OwnerID: org.ID}).(*Repository)
// remove a repo that does belong to org
- AssertExistsAndLoadBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
+ db.AssertExistsAndLoadBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
assert.NoError(t, org.RemoveOrgRepo(repo.ID))
- AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
- AssertExistsAndLoadBean(t, &Repository{ID: repo.ID}) // repo should still exist
+ db.AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
+ db.AssertExistsAndLoadBean(t, &Repository{ID: repo.ID}) // repo should still exist
// remove a repo that does not belong to org
assert.NoError(t, org.RemoveOrgRepo(repo.ID))
- AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
+ db.AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
- assert.NoError(t, org.RemoveOrgRepo(NonexistentID))
+ assert.NoError(t, org.RemoveOrgRepo(db.NonexistentID))
CheckConsistencyFor(t,
&User{ID: org.ID},
@@ -177,49 +178,49 @@ func TestUser_RemoveOrgRepo(t *testing.T) {
func TestCreateOrganization(t *testing.T) {
// successful creation of org
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
const newOrgName = "neworg"
org := &User{
Name: newOrgName,
}
- AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
assert.NoError(t, CreateOrganization(org, owner))
- org = AssertExistsAndLoadBean(t,
+ org = db.AssertExistsAndLoadBean(t,
&User{Name: newOrgName, Type: UserTypeOrganization}).(*User)
- ownerTeam := AssertExistsAndLoadBean(t,
+ ownerTeam := db.AssertExistsAndLoadBean(t,
&Team{Name: ownerTeamName, OrgID: org.ID}).(*Team)
- AssertExistsAndLoadBean(t, &TeamUser{UID: owner.ID, TeamID: ownerTeam.ID})
+ db.AssertExistsAndLoadBean(t, &TeamUser{UID: owner.ID, TeamID: ownerTeam.ID})
CheckConsistencyFor(t, &User{}, &Team{})
}
func TestCreateOrganization2(t *testing.T) {
// unauthorized creation of org
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
const newOrgName = "neworg"
org := &User{
Name: newOrgName,
}
- AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
err := CreateOrganization(org, owner)
assert.Error(t, err)
assert.True(t, IsErrUserNotAllowedCreateOrg(err))
- AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
CheckConsistencyFor(t, &User{}, &Team{})
}
func TestCreateOrganization3(t *testing.T) {
// create org with same name as existent org
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- org := &User{Name: "user3"} // should already exist
- AssertExistsAndLoadBean(t, &User{Name: org.Name}) // sanity check
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ org := &User{Name: "user3"} // should already exist
+ db.AssertExistsAndLoadBean(t, &User{Name: org.Name}) // sanity check
err := CreateOrganization(org, owner)
assert.Error(t, err)
assert.True(t, IsErrUserAlreadyExist(err))
@@ -228,9 +229,9 @@ func TestCreateOrganization3(t *testing.T) {
func TestCreateOrganization4(t *testing.T) {
// create org with unusable name
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
err := CreateOrganization(&User{Name: "assets"}, owner)
assert.Error(t, err)
assert.True(t, IsErrNameReserved(err))
@@ -238,7 +239,7 @@ func TestCreateOrganization4(t *testing.T) {
}
func TestGetOrgByName(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
org, err := GetOrgByName("user3")
assert.NoError(t, err)
@@ -253,32 +254,32 @@ func TestGetOrgByName(t *testing.T) {
}
func TestCountOrganizations(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- expected, err := x.Where("type=?", UserTypeOrganization).Count(&User{})
+ assert.NoError(t, db.PrepareTestDatabase())
+ expected, err := db.DefaultContext().Engine().Where("type=?", UserTypeOrganization).Count(&User{})
assert.NoError(t, err)
assert.Equal(t, expected, CountOrganizations())
}
func TestDeleteOrganization(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 6}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 6}).(*User)
assert.NoError(t, DeleteOrganization(org))
- AssertNotExistsBean(t, &User{ID: 6})
- AssertNotExistsBean(t, &OrgUser{OrgID: 6})
- AssertNotExistsBean(t, &Team{OrgID: 6})
+ db.AssertNotExistsBean(t, &User{ID: 6})
+ db.AssertNotExistsBean(t, &OrgUser{OrgID: 6})
+ db.AssertNotExistsBean(t, &Team{OrgID: 6})
- org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ org = db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
err := DeleteOrganization(org)
assert.Error(t, err)
assert.True(t, IsErrUserOwnRepos(err))
- user := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+ user := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
assert.Error(t, DeleteOrganization(user))
CheckConsistencyFor(t, &User{}, &Team{})
}
func TestIsOrganizationOwner(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
test := func(orgID, userID int64, expected bool) {
isOwner, err := IsOrganizationOwner(orgID, userID)
assert.NoError(t, err)
@@ -288,11 +289,11 @@ func TestIsOrganizationOwner(t *testing.T) {
test(3, 3, false)
test(6, 5, true)
test(6, 4, false)
- test(NonexistentID, NonexistentID, false)
+ test(db.NonexistentID, db.NonexistentID, false)
}
func TestIsOrganizationMember(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
test := func(orgID, userID int64, expected bool) {
isMember, err := IsOrganizationMember(orgID, userID)
assert.NoError(t, err)
@@ -303,11 +304,11 @@ func TestIsOrganizationMember(t *testing.T) {
test(3, 4, true)
test(6, 5, true)
test(6, 4, false)
- test(NonexistentID, NonexistentID, false)
+ test(db.NonexistentID, db.NonexistentID, false)
}
func TestIsPublicMembership(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
test := func(orgID, userID int64, expected bool) {
isMember, err := IsPublicMembership(orgID, userID)
assert.NoError(t, err)
@@ -318,11 +319,11 @@ func TestIsPublicMembership(t *testing.T) {
test(3, 4, false)
test(6, 5, true)
test(6, 4, false)
- test(NonexistentID, NonexistentID, false)
+ test(db.NonexistentID, db.NonexistentID, false)
}
func TestGetOrgsByUserID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
orgs, err := GetOrgsByUserID(4, true)
assert.NoError(t, err)
@@ -336,7 +337,7 @@ func TestGetOrgsByUserID(t *testing.T) {
}
func TestGetOwnedOrgsByUserID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
orgs, err := GetOwnedOrgsByUserID(2)
assert.NoError(t, err)
@@ -350,7 +351,7 @@ func TestGetOwnedOrgsByUserID(t *testing.T) {
}
func TestGetOwnedOrgsByUserIDDesc(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
orgs, err := GetOwnedOrgsByUserIDDesc(5, "id")
assert.NoError(t, err)
@@ -365,7 +366,7 @@ func TestGetOwnedOrgsByUserIDDesc(t *testing.T) {
}
func TestGetOrgUsersByUserID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
orgUsers, err := GetOrgUsersByUserID(5, &SearchOrganizationsOptions{All: true})
assert.NoError(t, err)
@@ -395,7 +396,7 @@ func TestGetOrgUsersByUserID(t *testing.T) {
}
func TestGetOrgUsersByOrgID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
orgUsers, err := GetOrgUsersByOrgID(&FindOrgMembersOpts{
ListOptions: ListOptions{},
@@ -420,7 +421,7 @@ func TestGetOrgUsersByOrgID(t *testing.T) {
orgUsers, err = GetOrgUsersByOrgID(&FindOrgMembersOpts{
ListOptions: ListOptions{},
- OrgID: NonexistentID,
+ OrgID: db.NonexistentID,
PublicOnly: false,
})
assert.NoError(t, err)
@@ -428,33 +429,33 @@ func TestGetOrgUsersByOrgID(t *testing.T) {
}
func TestChangeOrgUserStatus(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(orgID, userID int64, public bool) {
assert.NoError(t, ChangeOrgUserStatus(orgID, userID, public))
- orgUser := AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID}).(*OrgUser)
+ orgUser := db.AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID}).(*OrgUser)
assert.Equal(t, public, orgUser.IsPublic)
}
testSuccess(3, 2, false)
testSuccess(3, 2, false)
testSuccess(3, 4, true)
- assert.NoError(t, ChangeOrgUserStatus(NonexistentID, NonexistentID, true))
+ assert.NoError(t, ChangeOrgUserStatus(db.NonexistentID, db.NonexistentID, true))
}
func TestAddOrgUser(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(orgID, userID int64, isPublic bool) {
- org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+ org := db.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
expectedNumMembers := org.NumMembers
- if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
+ if !db.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
expectedNumMembers++
}
assert.NoError(t, AddOrgUser(orgID, userID))
ou := &OrgUser{OrgID: orgID, UID: userID}
- AssertExistsAndLoadBean(t, ou)
+ db.AssertExistsAndLoadBean(t, ou)
assert.Equal(t, isPublic, ou.IsPublic)
- org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+ org = db.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
assert.EqualValues(t, expectedNumMembers, org.NumMembers)
}
@@ -470,16 +471,16 @@ func TestAddOrgUser(t *testing.T) {
}
func TestRemoveOrgUser(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(orgID, userID int64) {
- org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+ org := db.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
expectedNumMembers := org.NumMembers
- if BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
+ if db.BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
expectedNumMembers--
}
assert.NoError(t, RemoveOrgUser(orgID, userID))
- AssertNotExistsBean(t, &OrgUser{OrgID: orgID, UID: userID})
- org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
+ db.AssertNotExistsBean(t, &OrgUser{OrgID: orgID, UID: userID})
+ org = db.AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
assert.EqualValues(t, expectedNumMembers, org.NumMembers)
}
testSuccess(3, 4)
@@ -488,13 +489,13 @@ func TestRemoveOrgUser(t *testing.T) {
err := RemoveOrgUser(7, 5)
assert.Error(t, err)
assert.True(t, IsErrLastOrgOwner(err))
- AssertExistsAndLoadBean(t, &OrgUser{OrgID: 7, UID: 5})
+ db.AssertExistsAndLoadBean(t, &OrgUser{OrgID: 7, UID: 5})
CheckConsistencyFor(t, &User{}, &Team{})
}
func TestUser_GetUserTeamIDs(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
testSuccess := func(userID int64, expected []int64) {
teamIDs, err := org.GetUserTeamIDs(userID)
assert.NoError(t, err)
@@ -502,12 +503,12 @@ func TestUser_GetUserTeamIDs(t *testing.T) {
}
testSuccess(2, []int64{1, 2})
testSuccess(4, []int64{2})
- testSuccess(NonexistentID, []int64{})
+ testSuccess(db.NonexistentID, []int64{})
}
func TestAccessibleReposEnv_CountRepos(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
testSuccess := func(userID, expectedCount int64) {
env, err := org.AccessibleReposEnv(userID)
assert.NoError(t, err)
@@ -520,8 +521,8 @@ func TestAccessibleReposEnv_CountRepos(t *testing.T) {
}
func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
testSuccess := func(userID, _, pageSize int64, expectedRepoIDs []int64) {
env, err := org.AccessibleReposEnv(userID)
assert.NoError(t, err)
@@ -534,8 +535,8 @@ func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
}
func TestAccessibleReposEnv_Repos(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
testSuccess := func(userID int64, expectedRepoIDs []int64) {
env, err := org.AccessibleReposEnv(userID)
assert.NoError(t, err)
@@ -543,7 +544,7 @@ func TestAccessibleReposEnv_Repos(t *testing.T) {
assert.NoError(t, err)
expectedRepos := make([]*Repository, len(expectedRepoIDs))
for i, repoID := range expectedRepoIDs {
- expectedRepos[i] = AssertExistsAndLoadBean(t,
+ expectedRepos[i] = db.AssertExistsAndLoadBean(t,
&Repository{ID: repoID}).(*Repository)
}
assert.Equal(t, expectedRepos, repos)
@@ -553,8 +554,8 @@ func TestAccessibleReposEnv_Repos(t *testing.T) {
}
func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
testSuccess := func(userID int64, expectedRepoIDs []int64) {
env, err := org.AccessibleReposEnv(userID)
assert.NoError(t, err)
@@ -562,7 +563,7 @@ func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
assert.NoError(t, err)
expectedRepos := make([]*Repository, len(expectedRepoIDs))
for i, repoID := range expectedRepoIDs {
- expectedRepos[i] = AssertExistsAndLoadBean(t,
+ expectedRepos[i] = db.AssertExistsAndLoadBean(t,
&Repository{ID: repoID}).(*Repository)
}
assert.Equal(t, expectedRepos, repos)
@@ -572,9 +573,9 @@ func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
}
func TestHasOrgVisibleTypePublic(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
const newOrgName = "test-org-public"
org := &User{
@@ -582,9 +583,9 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
Visibility: structs.VisibleTypePublic,
}
- AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
assert.NoError(t, CreateOrganization(org, owner))
- org = AssertExistsAndLoadBean(t,
+ org = db.AssertExistsAndLoadBean(t,
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
test1 := HasOrgOrUserVisible(org, owner)
test2 := HasOrgOrUserVisible(org, user3)
@@ -595,9 +596,9 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
}
func TestHasOrgVisibleTypeLimited(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
const newOrgName = "test-org-limited"
org := &User{
@@ -605,9 +606,9 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
Visibility: structs.VisibleTypeLimited,
}
- AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
assert.NoError(t, CreateOrganization(org, owner))
- org = AssertExistsAndLoadBean(t,
+ org = db.AssertExistsAndLoadBean(t,
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
test1 := HasOrgOrUserVisible(org, owner)
test2 := HasOrgOrUserVisible(org, user3)
@@ -618,9 +619,9 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
}
func TestHasOrgVisibleTypePrivate(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
const newOrgName = "test-org-private"
org := &User{
@@ -628,9 +629,9 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
Visibility: structs.VisibleTypePrivate,
}
- AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
+ db.AssertNotExistsBean(t, &User{Name: org.Name, Type: UserTypeOrganization})
assert.NoError(t, CreateOrganization(org, owner))
- org = AssertExistsAndLoadBean(t,
+ org = db.AssertExistsAndLoadBean(t,
&User{Name: org.Name, Type: UserTypeOrganization}).(*User)
test1 := HasOrgOrUserVisible(org, owner)
test2 := HasOrgOrUserVisible(org, user3)
@@ -641,7 +642,7 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
}
func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
users, err := GetUsersWhoCanCreateOrgRepo(3)
assert.NoError(t, err)