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.

repo_collaboration_test.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "code.gitea.io/gitea/models/db"
  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. "github.com/stretchr/testify/assert"
  12. )
  13. func TestRepository_AddCollaborator(t *testing.T) {
  14. assert.NoError(t, unittest.PrepareTestDatabase())
  15. testSuccess := func(repoID, userID int64) {
  16. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}).(*repo_model.Repository)
  17. assert.NoError(t, repo.GetOwner(db.DefaultContext))
  18. user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User)
  19. assert.NoError(t, AddCollaborator(repo, user))
  20. unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}, &user_model.User{ID: userID})
  21. }
  22. testSuccess(1, 4)
  23. testSuccess(1, 4)
  24. testSuccess(3, 4)
  25. }
  26. func TestRepository_DeleteCollaboration(t *testing.T) {
  27. assert.NoError(t, unittest.PrepareTestDatabase())
  28. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}).(*repo_model.Repository)
  29. assert.NoError(t, repo.GetOwner(db.DefaultContext))
  30. assert.NoError(t, DeleteCollaboration(repo, 4))
  31. unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4})
  32. assert.NoError(t, DeleteCollaboration(repo, 4))
  33. unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4})
  34. unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repo.ID})
  35. }