gitea源码

delete_test.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repository_test
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/models/organization"
  7. repo_model "code.gitea.io/gitea/models/repo"
  8. "code.gitea.io/gitea/models/unittest"
  9. user_model "code.gitea.io/gitea/models/user"
  10. repo_service "code.gitea.io/gitea/services/repository"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestTeam_HasRepository(t *testing.T) {
  14. assert.NoError(t, unittest.PrepareTestDatabase())
  15. test := func(teamID, repoID int64, expected bool) {
  16. team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
  17. assert.Equal(t, expected, repo_service.HasRepository(t.Context(), team, repoID))
  18. }
  19. test(1, 1, false)
  20. test(1, 3, true)
  21. test(1, 5, true)
  22. test(1, unittest.NonexistentID, false)
  23. test(2, 3, true)
  24. test(2, 5, false)
  25. }
  26. func TestTeam_RemoveRepository(t *testing.T) {
  27. assert.NoError(t, unittest.PrepareTestDatabase())
  28. testSuccess := func(teamID, repoID int64) {
  29. team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
  30. assert.NoError(t, repo_service.RemoveRepositoryFromTeam(t.Context(), team, repoID))
  31. unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
  32. unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
  33. }
  34. testSuccess(2, 3)
  35. testSuccess(2, 5)
  36. testSuccess(1, unittest.NonexistentID)
  37. }
  38. func TestDeleteOwnerRepositoriesDirectly(t *testing.T) {
  39. unittest.PrepareTestEnv(t)
  40. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
  41. assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(t.Context(), user))
  42. }