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.

delete_test.go 1.7KB

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/db"
  7. "code.gitea.io/gitea/models/organization"
  8. repo_model "code.gitea.io/gitea/models/repo"
  9. "code.gitea.io/gitea/models/unittest"
  10. user_model "code.gitea.io/gitea/models/user"
  11. repo_service "code.gitea.io/gitea/services/repository"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestTeam_HasRepository(t *testing.T) {
  15. assert.NoError(t, unittest.PrepareTestDatabase())
  16. test := func(teamID, repoID int64, expected bool) {
  17. team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
  18. assert.Equal(t, expected, repo_service.HasRepository(db.DefaultContext, team, repoID))
  19. }
  20. test(1, 1, false)
  21. test(1, 3, true)
  22. test(1, 5, true)
  23. test(1, unittest.NonexistentID, false)
  24. test(2, 3, true)
  25. test(2, 5, false)
  26. }
  27. func TestTeam_RemoveRepository(t *testing.T) {
  28. assert.NoError(t, unittest.PrepareTestDatabase())
  29. testSuccess := func(teamID, repoID int64) {
  30. team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
  31. assert.NoError(t, repo_service.RemoveRepositoryFromTeam(db.DefaultContext, team, repoID))
  32. unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
  33. unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
  34. }
  35. testSuccess(2, 3)
  36. testSuccess(2, 5)
  37. testSuccess(1, unittest.NonexistentID)
  38. }
  39. func TestDeleteOwnerRepositoriesDirectly(t *testing.T) {
  40. unittest.PrepareTestEnv(t)
  41. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
  42. assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user))
  43. }