You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

536 lines
16 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestUser_IsOwnedBy(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  12. assert.True(t, org.IsOwnedBy(2))
  13. assert.False(t, org.IsOwnedBy(1))
  14. assert.False(t, org.IsOwnedBy(3))
  15. assert.False(t, org.IsOwnedBy(4))
  16. nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  17. assert.False(t, nonOrg.IsOwnedBy(2))
  18. assert.False(t, nonOrg.IsOwnedBy(3))
  19. }
  20. func TestUser_IsOrgMember(t *testing.T) {
  21. assert.NoError(t, PrepareTestDatabase())
  22. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  23. assert.True(t, org.IsOrgMember(2))
  24. assert.True(t, org.IsOrgMember(4))
  25. assert.False(t, org.IsOrgMember(1))
  26. assert.False(t, org.IsOrgMember(3))
  27. nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  28. assert.False(t, nonOrg.IsOrgMember(2))
  29. assert.False(t, nonOrg.IsOrgMember(3))
  30. }
  31. func TestUser_GetTeam(t *testing.T) {
  32. assert.NoError(t, PrepareTestDatabase())
  33. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  34. team, err := org.GetTeam("team1")
  35. assert.NoError(t, err)
  36. assert.Equal(t, org.ID, team.OrgID)
  37. assert.Equal(t, "team1", team.LowerName)
  38. _, err = org.GetTeam("does not exist")
  39. assert.Equal(t, ErrTeamNotExist, err)
  40. nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  41. _, err = nonOrg.GetTeam("team")
  42. assert.Equal(t, ErrTeamNotExist, err)
  43. }
  44. func TestUser_GetOwnerTeam(t *testing.T) {
  45. assert.NoError(t, PrepareTestDatabase())
  46. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  47. team, err := org.GetOwnerTeam()
  48. assert.NoError(t, err)
  49. assert.Equal(t, org.ID, team.OrgID)
  50. nonOrg := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  51. _, err = nonOrg.GetOwnerTeam()
  52. assert.Equal(t, ErrTeamNotExist, err)
  53. }
  54. func TestUser_GetTeams(t *testing.T) {
  55. assert.NoError(t, PrepareTestDatabase())
  56. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  57. assert.NoError(t, org.GetTeams())
  58. assert.Len(t, org.Teams, 2)
  59. assert.Equal(t, int64(1), org.Teams[0].ID)
  60. assert.Equal(t, int64(2), org.Teams[1].ID)
  61. }
  62. func TestUser_GetMembers(t *testing.T) {
  63. assert.NoError(t, PrepareTestDatabase())
  64. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  65. assert.NoError(t, org.GetMembers())
  66. assert.Len(t, org.Members, 2)
  67. assert.Equal(t, int64(2), org.Members[0].ID)
  68. assert.Equal(t, int64(4), org.Members[1].ID)
  69. }
  70. func TestUser_AddMember(t *testing.T) {
  71. assert.NoError(t, PrepareTestDatabase())
  72. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  73. // add a user that is not a member
  74. AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
  75. prevNumMembers := org.NumMembers
  76. assert.NoError(t, org.AddMember(5))
  77. AssertExistsAndLoadBean(t, &OrgUser{UID: 5, OrgID: 3})
  78. org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  79. assert.Equal(t, prevNumMembers+1, org.NumMembers)
  80. // add a user that is already a member
  81. AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
  82. prevNumMembers = org.NumMembers
  83. assert.NoError(t, org.AddMember(4))
  84. AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
  85. org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  86. assert.Equal(t, prevNumMembers, org.NumMembers)
  87. CheckConsistencyFor(t, &User{})
  88. }
  89. func TestUser_RemoveMember(t *testing.T) {
  90. assert.NoError(t, PrepareTestDatabase())
  91. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  92. // remove a user that is a member
  93. AssertExistsAndLoadBean(t, &OrgUser{UID: 4, OrgID: 3})
  94. prevNumMembers := org.NumMembers
  95. assert.NoError(t, org.RemoveMember(4))
  96. AssertNotExistsBean(t, &OrgUser{UID: 4, OrgID: 3})
  97. org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  98. assert.Equal(t, prevNumMembers-1, org.NumMembers)
  99. // remove a user that is not a member
  100. AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
  101. prevNumMembers = org.NumMembers
  102. assert.NoError(t, org.RemoveMember(5))
  103. AssertNotExistsBean(t, &OrgUser{UID: 5, OrgID: 3})
  104. org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  105. assert.Equal(t, prevNumMembers, org.NumMembers)
  106. CheckConsistencyFor(t, &User{}, &Team{})
  107. }
  108. func TestUser_RemoveOrgRepo(t *testing.T) {
  109. assert.NoError(t, PrepareTestDatabase())
  110. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  111. repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: org.ID}).(*Repository)
  112. // remove a repo that does belong to org
  113. AssertExistsAndLoadBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
  114. assert.NoError(t, org.RemoveOrgRepo(repo.ID))
  115. AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
  116. AssertExistsAndLoadBean(t, &Repository{ID: repo.ID}) // repo should still exist
  117. // remove a repo that does not belong to org
  118. assert.NoError(t, org.RemoveOrgRepo(repo.ID))
  119. AssertNotExistsBean(t, &TeamRepo{RepoID: repo.ID, OrgID: org.ID})
  120. assert.NoError(t, org.RemoveOrgRepo(NonexistentID))
  121. CheckConsistencyFor(t,
  122. &User{ID: org.ID},
  123. &Team{OrgID: org.ID},
  124. &Repository{ID: repo.ID})
  125. }
  126. func TestCreateOrganization(t *testing.T) {
  127. // successful creation of org
  128. assert.NoError(t, PrepareTestDatabase())
  129. owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  130. const newOrgName = "neworg"
  131. org := &User{
  132. Name: newOrgName,
  133. }
  134. AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
  135. assert.NoError(t, CreateOrganization(org, owner))
  136. org = AssertExistsAndLoadBean(t,
  137. &User{Name: newOrgName, Type: UserTypeOrganization}).(*User)
  138. ownerTeam := AssertExistsAndLoadBean(t,
  139. &Team{Name: ownerTeamName, OrgID: org.ID}).(*Team)
  140. AssertExistsAndLoadBean(t, &TeamUser{UID: owner.ID, TeamID: ownerTeam.ID})
  141. CheckConsistencyFor(t, &User{}, &Team{})
  142. }
  143. func TestCreateOrganization2(t *testing.T) {
  144. // unauthorized creation of org
  145. assert.NoError(t, PrepareTestDatabase())
  146. owner := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
  147. const newOrgName = "neworg"
  148. org := &User{
  149. Name: newOrgName,
  150. }
  151. AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
  152. err := CreateOrganization(org, owner)
  153. assert.Error(t, err)
  154. assert.True(t, IsErrUserNotAllowedCreateOrg(err))
  155. AssertNotExistsBean(t, &User{Name: newOrgName, Type: UserTypeOrganization})
  156. CheckConsistencyFor(t, &User{}, &Team{})
  157. }
  158. func TestCreateOrganization3(t *testing.T) {
  159. // create org with same name as existent org
  160. assert.NoError(t, PrepareTestDatabase())
  161. owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  162. org := &User{Name: "user3"} // should already exist
  163. AssertExistsAndLoadBean(t, &User{Name: org.Name}) // sanity check
  164. err := CreateOrganization(org, owner)
  165. assert.Error(t, err)
  166. assert.True(t, IsErrUserAlreadyExist(err))
  167. CheckConsistencyFor(t, &User{}, &Team{})
  168. }
  169. func TestCreateOrganization4(t *testing.T) {
  170. // create org with unusable name
  171. assert.NoError(t, PrepareTestDatabase())
  172. owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  173. err := CreateOrganization(&User{Name: "assets"}, owner)
  174. assert.Error(t, err)
  175. assert.True(t, IsErrNameReserved(err))
  176. CheckConsistencyFor(t, &User{}, &Team{})
  177. }
  178. func TestGetOrgByName(t *testing.T) {
  179. assert.NoError(t, PrepareTestDatabase())
  180. org, err := GetOrgByName("user3")
  181. assert.NoError(t, err)
  182. assert.EqualValues(t, 3, org.ID)
  183. assert.Equal(t, "user3", org.Name)
  184. org, err = GetOrgByName("user2") // user2 is an individual
  185. assert.True(t, IsErrOrgNotExist(err))
  186. org, err = GetOrgByName("") // corner case
  187. assert.True(t, IsErrOrgNotExist(err))
  188. }
  189. func TestCountOrganizations(t *testing.T) {
  190. assert.NoError(t, PrepareTestDatabase())
  191. expected, err := x.Where("type=?", UserTypeOrganization).Count(&User{})
  192. assert.NoError(t, err)
  193. assert.Equal(t, expected, CountOrganizations())
  194. }
  195. func TestOrganizations(t *testing.T) {
  196. assert.NoError(t, PrepareTestDatabase())
  197. testSuccess := func(opts *SearchUserOptions, expectedOrgIDs []int64) {
  198. orgs, err := Organizations(opts)
  199. assert.NoError(t, err)
  200. assert.Len(t, orgs, len(expectedOrgIDs))
  201. for i, expectedOrgID := range expectedOrgIDs {
  202. assert.EqualValues(t, expectedOrgID, orgs[i].ID)
  203. }
  204. }
  205. testSuccess(&SearchUserOptions{OrderBy: "id ASC", Page: 1, PageSize: 2},
  206. []int64{3, 6})
  207. testSuccess(&SearchUserOptions{OrderBy: "id ASC", Page: 2, PageSize: 2},
  208. []int64{7})
  209. testSuccess(&SearchUserOptions{Page: 3, PageSize: 2},
  210. []int64{})
  211. }
  212. func TestDeleteOrganization(t *testing.T) {
  213. assert.NoError(t, PrepareTestDatabase())
  214. org := AssertExistsAndLoadBean(t, &User{ID: 6}).(*User)
  215. assert.NoError(t, DeleteOrganization(org))
  216. AssertNotExistsBean(t, &User{ID: 6})
  217. AssertNotExistsBean(t, &OrgUser{OrgID: 6})
  218. AssertNotExistsBean(t, &Team{OrgID: 6})
  219. org = AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  220. err := DeleteOrganization(org)
  221. assert.Error(t, err)
  222. assert.True(t, IsErrUserOwnRepos(err))
  223. nonOrg := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
  224. assert.Error(t, DeleteOrganization(nonOrg))
  225. CheckConsistencyFor(t, &User{}, &Team{})
  226. }
  227. func TestIsOrganizationOwner(t *testing.T) {
  228. assert.NoError(t, PrepareTestDatabase())
  229. assert.True(t, IsOrganizationOwner(3, 2))
  230. assert.False(t, IsOrganizationOwner(3, 3))
  231. assert.True(t, IsOrganizationOwner(6, 5))
  232. assert.False(t, IsOrganizationOwner(6, 4))
  233. assert.False(t, IsOrganizationOwner(NonexistentID, NonexistentID))
  234. }
  235. func TestIsOrganizationMember(t *testing.T) {
  236. assert.NoError(t, PrepareTestDatabase())
  237. assert.True(t, IsOrganizationMember(3, 2))
  238. assert.False(t, IsOrganizationMember(3, 3))
  239. assert.True(t, IsOrganizationMember(3, 4))
  240. assert.True(t, IsOrganizationMember(6, 5))
  241. assert.False(t, IsOrganizationMember(6, 4))
  242. assert.False(t, IsOrganizationMember(NonexistentID, NonexistentID))
  243. }
  244. func TestIsPublicMembership(t *testing.T) {
  245. assert.NoError(t, PrepareTestDatabase())
  246. assert.True(t, IsPublicMembership(3, 2))
  247. assert.False(t, IsPublicMembership(3, 3))
  248. assert.False(t, IsPublicMembership(3, 4))
  249. assert.True(t, IsPublicMembership(6, 5))
  250. assert.False(t, IsPublicMembership(6, 4))
  251. assert.False(t, IsPublicMembership(NonexistentID, NonexistentID))
  252. }
  253. func TestGetOrgsByUserID(t *testing.T) {
  254. assert.NoError(t, PrepareTestDatabase())
  255. orgs, err := GetOrgsByUserID(4, true)
  256. assert.NoError(t, err)
  257. assert.Len(t, orgs, 1)
  258. assert.EqualValues(t, 3, orgs[0].ID)
  259. orgs, err = GetOrgsByUserID(4, false)
  260. assert.NoError(t, err)
  261. assert.Len(t, orgs, 0)
  262. }
  263. func TestGetOwnedOrgsByUserID(t *testing.T) {
  264. assert.NoError(t, PrepareTestDatabase())
  265. orgs, err := GetOwnedOrgsByUserID(2)
  266. assert.NoError(t, err)
  267. assert.Len(t, orgs, 1)
  268. assert.EqualValues(t, 3, orgs[0].ID)
  269. orgs, err = GetOwnedOrgsByUserID(4)
  270. assert.NoError(t, err)
  271. assert.Len(t, orgs, 0)
  272. }
  273. func TestGetOwnedOrgsByUserIDDesc(t *testing.T) {
  274. assert.NoError(t, PrepareTestDatabase())
  275. orgs, err := GetOwnedOrgsByUserIDDesc(5, "id")
  276. assert.NoError(t, err)
  277. assert.Len(t, orgs, 2)
  278. assert.EqualValues(t, 7, orgs[0].ID)
  279. assert.EqualValues(t, 6, orgs[1].ID)
  280. orgs, err = GetOwnedOrgsByUserIDDesc(4, "id")
  281. assert.NoError(t, err)
  282. assert.Len(t, orgs, 0)
  283. }
  284. func TestGetOrgUsersByUserID(t *testing.T) {
  285. assert.NoError(t, PrepareTestDatabase())
  286. orgUsers, err := GetOrgUsersByUserID(5, true)
  287. assert.NoError(t, err)
  288. assert.Len(t, orgUsers, 2)
  289. assert.Equal(t, OrgUser{
  290. ID: orgUsers[0].ID,
  291. OrgID: 6,
  292. UID: 5,
  293. IsOwner: true,
  294. IsPublic: true,
  295. NumTeams: 1}, *orgUsers[0])
  296. assert.Equal(t, OrgUser{
  297. ID: orgUsers[1].ID,
  298. OrgID: 7,
  299. UID: 5,
  300. IsOwner: true,
  301. IsPublic: false,
  302. NumTeams: 1}, *orgUsers[1])
  303. publicOrgUsers, err := GetOrgUsersByUserID(5, false)
  304. assert.NoError(t, err)
  305. assert.Len(t, publicOrgUsers, 1)
  306. assert.Equal(t, *orgUsers[0], *publicOrgUsers[0])
  307. orgUsers, err = GetOrgUsersByUserID(1, true)
  308. assert.NoError(t, err)
  309. assert.Len(t, orgUsers, 0)
  310. }
  311. func TestGetOrgUsersByOrgID(t *testing.T) {
  312. assert.NoError(t, PrepareTestDatabase())
  313. orgUsers, err := GetOrgUsersByOrgID(3)
  314. assert.NoError(t, err)
  315. assert.Len(t, orgUsers, 2)
  316. assert.Equal(t, OrgUser{
  317. ID: orgUsers[0].ID,
  318. OrgID: 3,
  319. UID: 2,
  320. IsOwner: true,
  321. IsPublic: true,
  322. NumTeams: 1}, *orgUsers[0])
  323. assert.Equal(t, OrgUser{
  324. ID: orgUsers[1].ID,
  325. OrgID: 3,
  326. UID: 4,
  327. IsOwner: false,
  328. IsPublic: false,
  329. NumTeams: 0}, *orgUsers[1])
  330. orgUsers, err = GetOrgUsersByOrgID(NonexistentID)
  331. assert.NoError(t, err)
  332. assert.Len(t, orgUsers, 0)
  333. }
  334. func TestChangeOrgUserStatus(t *testing.T) {
  335. assert.NoError(t, PrepareTestDatabase())
  336. testSuccess := func(orgID, userID int64, public bool) {
  337. assert.NoError(t, ChangeOrgUserStatus(orgID, userID, public))
  338. orgUser := AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID}).(*OrgUser)
  339. assert.Equal(t, public, orgUser.IsPublic)
  340. }
  341. testSuccess(3, 2, false)
  342. testSuccess(3, 2, false)
  343. testSuccess(3, 4, true)
  344. assert.NoError(t, ChangeOrgUserStatus(NonexistentID, NonexistentID, true))
  345. }
  346. func TestAddOrgUser(t *testing.T) {
  347. assert.NoError(t, PrepareTestDatabase())
  348. testSuccess := func(orgID, userID int64) {
  349. org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
  350. expectedNumMembers := org.NumMembers
  351. if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
  352. expectedNumMembers++
  353. }
  354. assert.NoError(t, AddOrgUser(orgID, userID))
  355. AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID})
  356. org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
  357. assert.EqualValues(t, expectedNumMembers, org.NumMembers)
  358. }
  359. testSuccess(3, 5)
  360. testSuccess(3, 5)
  361. testSuccess(6, 2)
  362. CheckConsistencyFor(t, &User{}, &Team{})
  363. }
  364. func TestRemoveOrgUser(t *testing.T) {
  365. assert.NoError(t, PrepareTestDatabase())
  366. testSuccess := func(orgID, userID int64) {
  367. org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
  368. expectedNumMembers := org.NumMembers
  369. if BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
  370. expectedNumMembers--
  371. }
  372. assert.NoError(t, RemoveOrgUser(orgID, userID))
  373. AssertNotExistsBean(t, &OrgUser{OrgID: orgID, UID: userID})
  374. org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
  375. assert.EqualValues(t, expectedNumMembers, org.NumMembers)
  376. }
  377. testSuccess(3, 4)
  378. testSuccess(3, 4)
  379. err := RemoveOrgUser(7, 5)
  380. assert.Error(t, err)
  381. assert.True(t, IsErrLastOrgOwner(err))
  382. AssertExistsAndLoadBean(t, &OrgUser{OrgID: 7, UID: 5})
  383. CheckConsistencyFor(t, &User{}, &Team{})
  384. }
  385. func TestUser_GetUserTeamIDs(t *testing.T) {
  386. assert.NoError(t, PrepareTestDatabase())
  387. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  388. testSuccess := func(userID int64, expected []int64) {
  389. teamIDs, err := org.GetUserTeamIDs(userID)
  390. assert.NoError(t, err)
  391. assert.Equal(t, expected, teamIDs)
  392. }
  393. testSuccess(2, []int64{1, 2})
  394. testSuccess(4, []int64{2})
  395. testSuccess(NonexistentID, []int64{})
  396. }
  397. func TestAccessibleReposEnv_CountRepos(t *testing.T) {
  398. assert.NoError(t, PrepareTestDatabase())
  399. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  400. testSuccess := func(userID, expectedCount int64) {
  401. env, err := org.AccessibleReposEnv(userID)
  402. assert.NoError(t, err)
  403. count, err := env.CountRepos()
  404. assert.NoError(t, err)
  405. assert.EqualValues(t, expectedCount, count)
  406. }
  407. testSuccess(2, 2)
  408. testSuccess(4, 1)
  409. }
  410. func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
  411. assert.NoError(t, PrepareTestDatabase())
  412. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  413. testSuccess := func(userID, page, pageSize int64, expectedRepoIDs []int64) {
  414. env, err := org.AccessibleReposEnv(userID)
  415. assert.NoError(t, err)
  416. repoIDs, err := env.RepoIDs(1, 100)
  417. assert.NoError(t, err)
  418. assert.Equal(t, expectedRepoIDs, repoIDs)
  419. }
  420. testSuccess(2, 1, 100, []int64{3, 5})
  421. testSuccess(4, 0, 100, []int64{3})
  422. }
  423. func TestAccessibleReposEnv_Repos(t *testing.T) {
  424. assert.NoError(t, PrepareTestDatabase())
  425. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  426. testSuccess := func(userID int64, expectedRepoIDs []int64) {
  427. env, err := org.AccessibleReposEnv(userID)
  428. assert.NoError(t, err)
  429. repos, err := env.Repos(1, 100)
  430. assert.NoError(t, err)
  431. expectedRepos := make([]*Repository, len(expectedRepoIDs))
  432. for i, repoID := range expectedRepoIDs {
  433. expectedRepos[i] = AssertExistsAndLoadBean(t,
  434. &Repository{ID: repoID}).(*Repository)
  435. }
  436. assert.Equal(t, expectedRepos, repos)
  437. }
  438. testSuccess(2, []int64{3, 5})
  439. testSuccess(4, []int64{3})
  440. }
  441. func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {
  442. assert.NoError(t, PrepareTestDatabase())
  443. org := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  444. testSuccess := func(userID int64, expectedRepoIDs []int64) {
  445. env, err := org.AccessibleReposEnv(userID)
  446. assert.NoError(t, err)
  447. repos, err := env.MirrorRepos()
  448. assert.NoError(t, err)
  449. expectedRepos := make([]*Repository, len(expectedRepoIDs))
  450. for i, repoID := range expectedRepoIDs {
  451. expectedRepos[i] = AssertExistsAndLoadBean(t,
  452. &Repository{ID: repoID}).(*Repository)
  453. }
  454. assert.Equal(t, expectedRepos, repos)
  455. }
  456. testSuccess(2, []int64{5})
  457. testSuccess(4, []int64{})
  458. }