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.

star_test.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 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 TestStarRepo(t *testing.T) {
  12. assert.NoError(t, unittest.PrepareTestDatabase())
  13. const userID = 2
  14. const repoID = 1
  15. unittest.AssertNotExistsBean(t, &Star{UID: userID, RepoID: repoID})
  16. assert.NoError(t, StarRepo(userID, repoID, true))
  17. unittest.AssertExistsAndLoadBean(t, &Star{UID: userID, RepoID: repoID})
  18. assert.NoError(t, StarRepo(userID, repoID, true))
  19. unittest.AssertExistsAndLoadBean(t, &Star{UID: userID, RepoID: repoID})
  20. assert.NoError(t, StarRepo(userID, repoID, false))
  21. unittest.AssertNotExistsBean(t, &Star{UID: userID, RepoID: repoID})
  22. }
  23. func TestIsStaring(t *testing.T) {
  24. assert.NoError(t, unittest.PrepareTestDatabase())
  25. assert.True(t, IsStaring(db.DefaultContext, 2, 4))
  26. assert.False(t, IsStaring(db.DefaultContext, 3, 4))
  27. }
  28. func TestRepository_GetStargazers(t *testing.T) {
  29. // repo with stargazers
  30. assert.NoError(t, unittest.PrepareTestDatabase())
  31. repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository)
  32. gazers, err := GetStargazers(repo, db.ListOptions{Page: 0})
  33. assert.NoError(t, err)
  34. if assert.Len(t, gazers, 1) {
  35. assert.Equal(t, int64(2), gazers[0].ID)
  36. }
  37. }
  38. func TestRepository_GetStargazers2(t *testing.T) {
  39. // repo with stargazers
  40. assert.NoError(t, unittest.PrepareTestDatabase())
  41. repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
  42. gazers, err := GetStargazers(repo, db.ListOptions{Page: 0})
  43. assert.NoError(t, err)
  44. assert.Len(t, gazers, 0)
  45. }