您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

collaboration_test.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2022 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 repo
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models/db"
  8. "code.gitea.io/gitea/models/unittest"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestRepository_GetCollaborators(t *testing.T) {
  12. assert.NoError(t, unittest.PrepareTestDatabase())
  13. test := func(repoID int64) {
  14. repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
  15. collaborators, err := GetCollaborators(db.DefaultContext, repo.ID, db.ListOptions{})
  16. assert.NoError(t, err)
  17. expectedLen, err := db.GetEngine(db.DefaultContext).Count(&Collaboration{RepoID: repoID})
  18. assert.NoError(t, err)
  19. assert.Len(t, collaborators, int(expectedLen))
  20. for _, collaborator := range collaborators {
  21. assert.EqualValues(t, collaborator.User.ID, collaborator.Collaboration.UserID)
  22. assert.EqualValues(t, repoID, collaborator.Collaboration.RepoID)
  23. }
  24. }
  25. test(1)
  26. test(2)
  27. test(3)
  28. test(4)
  29. }
  30. func TestRepository_IsCollaborator(t *testing.T) {
  31. assert.NoError(t, unittest.PrepareTestDatabase())
  32. test := func(repoID, userID int64, expected bool) {
  33. repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
  34. actual, err := IsCollaborator(db.DefaultContext, repo.ID, userID)
  35. assert.NoError(t, err)
  36. assert.Equal(t, expected, actual)
  37. }
  38. test(3, 2, true)
  39. test(3, unittest.NonexistentID, false)
  40. test(4, 2, false)
  41. test(4, 4, true)
  42. }