summaryrefslogtreecommitdiffstats
path: root/models/repo_watch_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo_watch_test.go')
-rw-r--r--models/repo_watch_test.go57
1 files changed, 29 insertions, 28 deletions
diff --git a/models/repo_watch_test.go b/models/repo_watch_test.go
index e1bbc40238..1a94b8ad30 100644
--- a/models/repo_watch_test.go
+++ b/models/repo_watch_test.go
@@ -7,13 +7,14 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
func TestIsWatching(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
assert.True(t, IsWatching(1, 1))
assert.True(t, IsWatching(4, 1))
@@ -21,27 +22,27 @@ func TestIsWatching(t *testing.T) {
assert.False(t, IsWatching(1, 5))
assert.False(t, IsWatching(8, 1))
- assert.False(t, IsWatching(NonexistentID, NonexistentID))
+ assert.False(t, IsWatching(db.NonexistentID, db.NonexistentID))
}
func TestWatchRepo(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
const repoID = 3
const userID = 2
assert.NoError(t, WatchRepo(userID, repoID, true))
- AssertExistsAndLoadBean(t, &Watch{RepoID: repoID, UserID: userID})
+ db.AssertExistsAndLoadBean(t, &Watch{RepoID: repoID, UserID: userID})
CheckConsistencyFor(t, &Repository{ID: repoID})
assert.NoError(t, WatchRepo(userID, repoID, false))
- AssertNotExistsBean(t, &Watch{RepoID: repoID, UserID: userID})
+ db.AssertNotExistsBean(t, &Watch{RepoID: repoID, UserID: userID})
CheckConsistencyFor(t, &Repository{ID: repoID})
}
func TestGetWatchers(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
+ repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watches, err := GetWatchers(repo.ID)
assert.NoError(t, err)
// One watchers are inactive, thus minus 1
@@ -50,30 +51,30 @@ func TestGetWatchers(t *testing.T) {
assert.EqualValues(t, repo.ID, watch.RepoID)
}
- watches, err = GetWatchers(NonexistentID)
+ watches, err = GetWatchers(db.NonexistentID)
assert.NoError(t, err)
assert.Len(t, watches, 0)
}
func TestRepository_GetWatchers(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
+ repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watchers, err := repo.GetWatchers(ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
for _, watcher := range watchers {
- AssertExistsAndLoadBean(t, &Watch{UserID: watcher.ID, RepoID: repo.ID})
+ db.AssertExistsAndLoadBean(t, &Watch{UserID: watcher.ID, RepoID: repo.ID})
}
- repo = AssertExistsAndLoadBean(t, &Repository{ID: 9}).(*Repository)
+ repo = db.AssertExistsAndLoadBean(t, &Repository{ID: 9}).(*Repository)
watchers, err = repo.GetWatchers(ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, 0)
}
func TestNotifyWatchers(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
action := &Action{
ActUserID: 8,
@@ -83,25 +84,25 @@ func TestNotifyWatchers(t *testing.T) {
assert.NoError(t, NotifyWatchers(action))
// One watchers are inactive, thus action is only created for user 8, 1, 4, 11
- AssertExistsAndLoadBean(t, &Action{
+ db.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 8,
RepoID: action.RepoID,
OpType: action.OpType,
})
- AssertExistsAndLoadBean(t, &Action{
+ db.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 1,
RepoID: action.RepoID,
OpType: action.OpType,
})
- AssertExistsAndLoadBean(t, &Action{
+ db.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 4,
RepoID: action.RepoID,
OpType: action.OpType,
})
- AssertExistsAndLoadBean(t, &Action{
+ db.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 11,
RepoID: action.RepoID,
@@ -110,9 +111,9 @@ func TestNotifyWatchers(t *testing.T) {
}
func TestWatchIfAuto(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
+ repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watchers, err := repo.GetWatchers(ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
@@ -167,22 +168,22 @@ func TestWatchIfAuto(t *testing.T) {
}
func TestWatchRepoMode(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeAuto))
- AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
- AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeAuto}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeAuto}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeNormal))
- AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
- AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeNormal}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeNormal}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeDont))
- AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
- AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeDont}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeDont}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeNone))
- AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
+ db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
}