mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-02 21:02:09 +00:00
enable linter testifylint on v8 (#4573)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4573 Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
parent
4d2263e82e
commit
ce563ade3d
503 changed files with 5014 additions and 4665 deletions
|
@ -14,10 +14,11 @@ import (
|
|||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUser_IsOwnedBy(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
for _, testCase := range []struct {
|
||||
OrgID int64
|
||||
UserID int64
|
||||
|
@ -32,13 +33,13 @@ func TestUser_IsOwnedBy(t *testing.T) {
|
|||
} {
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID})
|
||||
isOwner, err := org.IsOwnedBy(db.DefaultContext, testCase.UserID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.ExpectedOwner, isOwner)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_IsOrgMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
for _, testCase := range []struct {
|
||||
OrgID int64
|
||||
UserID int64
|
||||
|
@ -53,16 +54,16 @@ func TestUser_IsOrgMember(t *testing.T) {
|
|||
} {
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: testCase.OrgID})
|
||||
isMember, err := org.IsOrgMember(db.DefaultContext, testCase.UserID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, testCase.ExpectedMember, isMember)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUser_GetTeam(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
team, err := org.GetTeam(db.DefaultContext, "team1")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, org.ID, team.OrgID)
|
||||
assert.Equal(t, "team1", team.LowerName)
|
||||
|
||||
|
@ -75,10 +76,10 @@ func TestUser_GetTeam(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUser_GetOwnerTeam(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
team, err := org.GetOwnerTeam(db.DefaultContext)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, org.ID, team.OrgID)
|
||||
|
||||
nonOrg := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 2})
|
||||
|
@ -87,10 +88,10 @@ func TestUser_GetOwnerTeam(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUser_GetTeams(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
teams, err := org.LoadTeams(db.DefaultContext)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, teams, 5) {
|
||||
assert.Equal(t, int64(1), teams[0].ID)
|
||||
assert.Equal(t, int64(2), teams[1].ID)
|
||||
|
@ -101,10 +102,10 @@ func TestUser_GetTeams(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUser_GetMembers(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
members, _, err := org.GetMembers(db.DefaultContext)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, members, 3) {
|
||||
assert.Equal(t, int64(2), members[0].ID)
|
||||
assert.Equal(t, int64(28), members[1].ID)
|
||||
|
@ -113,10 +114,10 @@ func TestUser_GetMembers(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetOrgByName(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
org, err := organization.GetOrgByName(db.DefaultContext, "org3")
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 3, org.ID)
|
||||
assert.Equal(t, "org3", org.Name)
|
||||
|
||||
|
@ -128,19 +129,19 @@ func TestGetOrgByName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCountOrganizations(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
expected, err := db.GetEngine(db.DefaultContext).Where("type=?", user_model.UserTypeOrganization).Count(&organization.Organization{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
cnt, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{IncludePrivate: true})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, cnt)
|
||||
}
|
||||
|
||||
func TestIsOrganizationOwner(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(orgID, userID int64, expected bool) {
|
||||
isOwner, err := organization.IsOrganizationOwner(db.DefaultContext, orgID, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, expected, isOwner)
|
||||
}
|
||||
test(3, 2, true)
|
||||
|
@ -151,10 +152,10 @@ func TestIsOrganizationOwner(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsOrganizationMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(orgID, userID int64, expected bool) {
|
||||
isMember, err := organization.IsOrganizationMember(db.DefaultContext, orgID, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, expected, isMember)
|
||||
}
|
||||
test(3, 2, true)
|
||||
|
@ -166,10 +167,10 @@ func TestIsOrganizationMember(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsPublicMembership(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(orgID, userID int64, expected bool) {
|
||||
isMember, err := organization.IsPublicMembership(db.DefaultContext, orgID, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, expected, isMember)
|
||||
}
|
||||
test(3, 2, true)
|
||||
|
@ -181,13 +182,13 @@ func TestIsPublicMembership(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFindOrgs(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
orgs, err := db.Find[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, orgs, 1) {
|
||||
assert.EqualValues(t, 3, orgs[0].ID)
|
||||
}
|
||||
|
@ -196,26 +197,26 @@ func TestFindOrgs(t *testing.T) {
|
|||
UserID: 4,
|
||||
IncludePrivate: false,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, orgs, 0)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, orgs)
|
||||
|
||||
total, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||
UserID: 4,
|
||||
IncludePrivate: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, 1, total)
|
||||
}
|
||||
|
||||
func TestGetOrgUsersByOrgID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
orgUsers, err := organization.GetOrgUsersByOrgID(db.DefaultContext, &organization.FindOrgMembersOpts{
|
||||
ListOptions: db.ListOptions{},
|
||||
OrgID: 3,
|
||||
PublicOnly: false,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
if assert.Len(t, orgUsers, 3) {
|
||||
assert.Equal(t, organization.OrgUser{
|
||||
ID: orgUsers[0].ID,
|
||||
|
@ -242,15 +243,15 @@ func TestGetOrgUsersByOrgID(t *testing.T) {
|
|||
OrgID: unittest.NonexistentID,
|
||||
PublicOnly: false,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, orgUsers, 0)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, orgUsers)
|
||||
}
|
||||
|
||||
func TestChangeOrgUserStatus(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
testSuccess := func(orgID, userID int64, public bool) {
|
||||
assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, orgID, userID, public))
|
||||
require.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, orgID, userID, public))
|
||||
orgUser := unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{OrgID: orgID, UID: userID})
|
||||
assert.Equal(t, public, orgUser.IsPublic)
|
||||
}
|
||||
|
@ -258,15 +259,15 @@ func TestChangeOrgUserStatus(t *testing.T) {
|
|||
testSuccess(3, 2, false)
|
||||
testSuccess(3, 2, false)
|
||||
testSuccess(3, 4, true)
|
||||
assert.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID, true))
|
||||
require.NoError(t, organization.ChangeOrgUserStatus(db.DefaultContext, unittest.NonexistentID, unittest.NonexistentID, true))
|
||||
}
|
||||
|
||||
func TestUser_GetUserTeamIDs(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess := func(userID int64, expected []int64) {
|
||||
teamIDs, err := org.GetUserTeamIDs(db.DefaultContext, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, teamIDs)
|
||||
}
|
||||
testSuccess(2, []int64{1, 2, 14})
|
||||
|
@ -275,13 +276,13 @@ func TestUser_GetUserTeamIDs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccessibleReposEnv_CountRepos(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess := func(userID, expectedCount int64) {
|
||||
env, err := organization.AccessibleReposEnv(db.DefaultContext, org, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
count, err := env.CountRepos()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.EqualValues(t, expectedCount, count)
|
||||
}
|
||||
testSuccess(2, 3)
|
||||
|
@ -289,13 +290,13 @@ func TestAccessibleReposEnv_CountRepos(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess := func(userID int64, expectedRepoIDs []int64) {
|
||||
env, err := organization.AccessibleReposEnv(db.DefaultContext, org, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
repoIDs, err := env.RepoIDs(1, 100)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedRepoIDs, repoIDs)
|
||||
}
|
||||
testSuccess(2, []int64{3, 5, 32})
|
||||
|
@ -303,13 +304,13 @@ func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccessibleReposEnv_Repos(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess := func(userID int64, expectedRepoIDs []int64) {
|
||||
env, err := organization.AccessibleReposEnv(db.DefaultContext, org, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
repos, err := env.Repos(1, 100)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
expectedRepos := make(repo_model.RepositoryList, len(expectedRepoIDs))
|
||||
for i, repoID := range expectedRepoIDs {
|
||||
expectedRepos[i] = unittest.AssertExistsAndLoadBean(t,
|
||||
|
@ -322,13 +323,13 @@ func TestAccessibleReposEnv_Repos(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess := func(userID int64, expectedRepoIDs []int64) {
|
||||
env, err := organization.AccessibleReposEnv(db.DefaultContext, org, userID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
repos, err := env.MirrorRepos()
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
expectedRepos := make(repo_model.RepositoryList, len(expectedRepoIDs))
|
||||
for i, repoID := range expectedRepoIDs {
|
||||
expectedRepos[i] = unittest.AssertExistsAndLoadBean(t,
|
||||
|
@ -341,7 +342,7 @@ func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHasOrgVisibleTypePublic(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
|
||||
|
@ -352,7 +353,7 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
|
|||
}
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
require.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
org = unittest.AssertExistsAndLoadBean(t,
|
||||
&organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner)
|
||||
|
@ -364,7 +365,7 @@ func TestHasOrgVisibleTypePublic(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHasOrgVisibleTypeLimited(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
|
||||
|
@ -375,7 +376,7 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
|
|||
}
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
require.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
org = unittest.AssertExistsAndLoadBean(t,
|
||||
&organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner)
|
||||
|
@ -387,7 +388,7 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestHasOrgVisibleTypePrivate(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
|
||||
|
@ -398,7 +399,7 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
|
|||
}
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
require.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
org = unittest.AssertExistsAndLoadBean(t,
|
||||
&organization.Organization{Name: org.Name, Type: user_model.UserTypeOrganization})
|
||||
test1 := organization.HasOrgOrUserVisible(db.DefaultContext, org.AsUser(), owner)
|
||||
|
@ -410,10 +411,10 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
users, err := organization.GetUsersWhoCanCreateOrgRepo(db.DefaultContext, 3)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, users, 2)
|
||||
var ids []int64
|
||||
for i := range users {
|
||||
|
@ -422,27 +423,27 @@ func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) {
|
|||
assert.ElementsMatch(t, ids, []int64{2, 28})
|
||||
|
||||
users, err = organization.GetUsersWhoCanCreateOrgRepo(db.DefaultContext, 7)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, users, 1)
|
||||
assert.NotNil(t, users[5])
|
||||
}
|
||||
|
||||
func TestUser_RemoveOrgRepo(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: org.ID})
|
||||
|
||||
// remove a repo that does belong to org
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
||||
assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID))
|
||||
require.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}) // repo should still exist
|
||||
|
||||
// remove a repo that does not belong to org
|
||||
assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID))
|
||||
require.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID})
|
||||
|
||||
assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, unittest.NonexistentID))
|
||||
require.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, unittest.NonexistentID))
|
||||
|
||||
unittest.CheckConsistencyFor(t,
|
||||
&user_model.User{ID: org.ID},
|
||||
|
@ -452,7 +453,7 @@ func TestUser_RemoveOrgRepo(t *testing.T) {
|
|||
|
||||
func TestCreateOrganization(t *testing.T) {
|
||||
// successful creation of org
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
const newOrgName = "neworg"
|
||||
|
@ -461,7 +462,7 @@ func TestCreateOrganization(t *testing.T) {
|
|||
}
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: newOrgName, Type: user_model.UserTypeOrganization})
|
||||
assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
require.NoError(t, organization.CreateOrganization(db.DefaultContext, org, owner))
|
||||
org = unittest.AssertExistsAndLoadBean(t,
|
||||
&organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization})
|
||||
ownerTeam := unittest.AssertExistsAndLoadBean(t,
|
||||
|
@ -472,7 +473,7 @@ func TestCreateOrganization(t *testing.T) {
|
|||
|
||||
func TestCreateOrganization2(t *testing.T) {
|
||||
// unauthorized creation of org
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
||||
const newOrgName = "neworg"
|
||||
|
@ -482,7 +483,7 @@ func TestCreateOrganization2(t *testing.T) {
|
|||
|
||||
unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization})
|
||||
err := organization.CreateOrganization(db.DefaultContext, org, owner)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, organization.IsErrUserNotAllowedCreateOrg(err))
|
||||
unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization})
|
||||
unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
|
||||
|
@ -490,24 +491,24 @@ func TestCreateOrganization2(t *testing.T) {
|
|||
|
||||
func TestCreateOrganization3(t *testing.T) {
|
||||
// create org with same name as existent org
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
org := &organization.Organization{Name: "org3"} // should already exist
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: org.Name}) // sanity check
|
||||
err := organization.CreateOrganization(db.DefaultContext, org, owner)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, user_model.IsErrUserAlreadyExist(err))
|
||||
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
|
||||
}
|
||||
|
||||
func TestCreateOrganization4(t *testing.T) {
|
||||
// create org with unusable name
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
err := organization.CreateOrganization(db.DefaultContext, &organization.Organization{Name: "assets"}, owner)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.True(t, db.IsErrNameReserved(err))
|
||||
unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue