|
5 | 5 | package models
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "fmt" |
9 | 8 | "strings"
|
10 | 9 | "testing"
|
11 | 10 |
|
12 |
| - "code.gitea.io/gitea/modules/structs" |
13 |
| - |
14 | 11 | "github.com/stretchr/testify/assert"
|
15 | 12 | )
|
16 | 13 |
|
@@ -377,133 +374,3 @@ func TestUsersInTeamsCount(t *testing.T) {
|
377 | 374 | test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4
|
378 | 375 | test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) // userid 2,4,5
|
379 | 376 | }
|
380 |
| - |
381 |
| -func TestIncludesAllRepositoriesTeams(t *testing.T) { |
382 |
| - assert.NoError(t, PrepareTestDatabase()) |
383 |
| - |
384 |
| - testTeamRepositories := func(teamID int64, repoIds []int64) { |
385 |
| - team := AssertExistsAndLoadBean(t, &Team{ID: teamID}).(*Team) |
386 |
| - assert.NoError(t, team.GetRepositories(), "%s: GetRepositories", team.Name) |
387 |
| - assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name) |
388 |
| - assert.Equal(t, len(repoIds), len(team.Repos), "%s: repo count", team.Name) |
389 |
| - for i, rid := range repoIds { |
390 |
| - if rid > 0 { |
391 |
| - assert.True(t, team.HasRepository(rid), "%s: HasRepository(%d) %d", rid, i) |
392 |
| - } |
393 |
| - } |
394 |
| - } |
395 |
| - |
396 |
| - // Get an admin user. |
397 |
| - user, err := GetUserByID(1) |
398 |
| - assert.NoError(t, err, "GetUserByID") |
399 |
| - |
400 |
| - // Create org. |
401 |
| - org := &User{ |
402 |
| - Name: "All repo", |
403 |
| - IsActive: true, |
404 |
| - Type: UserTypeOrganization, |
405 |
| - Visibility: structs.VisibleTypePublic, |
406 |
| - } |
407 |
| - assert.NoError(t, CreateOrganization(org, user), "CreateOrganization") |
408 |
| - |
409 |
| - // Check Owner team. |
410 |
| - ownerTeam, err := org.GetOwnerTeam() |
411 |
| - assert.NoError(t, err, "GetOwnerTeam") |
412 |
| - assert.True(t, ownerTeam.IncludesAllRepositories, "Owner team includes all repositories") |
413 |
| - |
414 |
| - // Create repos. |
415 |
| - repoIds := make([]int64, 0) |
416 |
| - for i := 0; i < 3; i++ { |
417 |
| - r, err := CreateRepository(user, org, CreateRepoOptions{Name: fmt.Sprintf("repo-%d", i)}) |
418 |
| - assert.NoError(t, err, "CreateRepository %d", i) |
419 |
| - if r != nil { |
420 |
| - repoIds = append(repoIds, r.ID) |
421 |
| - } |
422 |
| - } |
423 |
| - // Get fresh copy of Owner team after creating repos. |
424 |
| - ownerTeam, err = org.GetOwnerTeam() |
425 |
| - assert.NoError(t, err, "GetOwnerTeam") |
426 |
| - |
427 |
| - // Create teams and check repositories. |
428 |
| - teams := []*Team{ |
429 |
| - ownerTeam, |
430 |
| - { |
431 |
| - OrgID: org.ID, |
432 |
| - Name: "team one", |
433 |
| - Authorize: AccessModeRead, |
434 |
| - IncludesAllRepositories: true, |
435 |
| - }, |
436 |
| - { |
437 |
| - OrgID: org.ID, |
438 |
| - Name: "team 2", |
439 |
| - Authorize: AccessModeRead, |
440 |
| - IncludesAllRepositories: false, |
441 |
| - }, |
442 |
| - { |
443 |
| - OrgID: org.ID, |
444 |
| - Name: "team three", |
445 |
| - Authorize: AccessModeWrite, |
446 |
| - IncludesAllRepositories: true, |
447 |
| - }, |
448 |
| - { |
449 |
| - OrgID: org.ID, |
450 |
| - Name: "team 4", |
451 |
| - Authorize: AccessModeWrite, |
452 |
| - IncludesAllRepositories: false, |
453 |
| - }, |
454 |
| - } |
455 |
| - teamRepos := [][]int64{ |
456 |
| - repoIds, |
457 |
| - repoIds, |
458 |
| - {}, |
459 |
| - repoIds, |
460 |
| - {}, |
461 |
| - } |
462 |
| - for i, team := range teams { |
463 |
| - if i > 0 { // first team is Owner. |
464 |
| - assert.NoError(t, NewTeam(team), "%s: NewTeam", team.Name) |
465 |
| - } |
466 |
| - testTeamRepositories(team.ID, teamRepos[i]) |
467 |
| - } |
468 |
| - |
469 |
| - // Update teams and check repositories. |
470 |
| - teams[3].IncludesAllRepositories = false |
471 |
| - teams[4].IncludesAllRepositories = true |
472 |
| - teamRepos[4] = repoIds |
473 |
| - for i, team := range teams { |
474 |
| - assert.NoError(t, UpdateTeam(team, false, true), "%s: UpdateTeam", team.Name) |
475 |
| - testTeamRepositories(team.ID, teamRepos[i]) |
476 |
| - } |
477 |
| - |
478 |
| - // Create repo and check teams repositories. |
479 |
| - org.Teams = nil // Reset teams to allow their reloading. |
480 |
| - r, err := CreateRepository(user, org, CreateRepoOptions{Name: "repo-last"}) |
481 |
| - assert.NoError(t, err, "CreateRepository last") |
482 |
| - if r != nil { |
483 |
| - repoIds = append(repoIds, r.ID) |
484 |
| - } |
485 |
| - teamRepos[0] = repoIds |
486 |
| - teamRepos[1] = repoIds |
487 |
| - teamRepos[4] = repoIds |
488 |
| - for i, team := range teams { |
489 |
| - testTeamRepositories(team.ID, teamRepos[i]) |
490 |
| - } |
491 |
| - |
492 |
| - // Remove repo and check teams repositories. |
493 |
| - assert.NoError(t, DeleteRepository(user, org.ID, repoIds[0]), "DeleteRepository") |
494 |
| - teamRepos[0] = repoIds[1:] |
495 |
| - teamRepos[1] = repoIds[1:] |
496 |
| - teamRepos[3] = repoIds[1:3] |
497 |
| - teamRepos[4] = repoIds[1:] |
498 |
| - for i, team := range teams { |
499 |
| - testTeamRepositories(team.ID, teamRepos[i]) |
500 |
| - } |
501 |
| - |
502 |
| - // Wipe created items. |
503 |
| - for i, rid := range repoIds { |
504 |
| - if i > 0 { // first repo already deleted. |
505 |
| - assert.NoError(t, DeleteRepository(user, org.ID, rid), "DeleteRepository %d", i) |
506 |
| - } |
507 |
| - } |
508 |
| - assert.NoError(t, DeleteOrganization(org), "DeleteOrganization") |
509 |
| -} |
0 commit comments