Decouple unit test, remove intermediate unittestbridge package (#17662)

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
wxiaoguang 2021-11-16 16:53:21 +08:00 committed by GitHub
parent 23bd7b1211
commit 81926d61db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
151 changed files with 1719 additions and 1781 deletions

View file

@ -23,7 +23,7 @@ func TestIsWatching(t *testing.T) {
assert.False(t, IsWatching(1, 5))
assert.False(t, IsWatching(8, 1))
assert.False(t, IsWatching(db.NonexistentID, db.NonexistentID))
assert.False(t, IsWatching(unittest.NonexistentID, unittest.NonexistentID))
}
func TestWatchRepo(t *testing.T) {
@ -32,18 +32,18 @@ func TestWatchRepo(t *testing.T) {
const userID = 2
assert.NoError(t, WatchRepo(userID, repoID, true))
db.AssertExistsAndLoadBean(t, &Watch{RepoID: repoID, UserID: userID})
CheckConsistencyFor(t, &Repository{ID: repoID})
unittest.AssertExistsAndLoadBean(t, &Watch{RepoID: repoID, UserID: userID})
unittest.CheckConsistencyFor(t, &Repository{ID: repoID})
assert.NoError(t, WatchRepo(userID, repoID, false))
db.AssertNotExistsBean(t, &Watch{RepoID: repoID, UserID: userID})
CheckConsistencyFor(t, &Repository{ID: repoID})
unittest.AssertNotExistsBean(t, &Watch{RepoID: repoID, UserID: userID})
unittest.CheckConsistencyFor(t, &Repository{ID: repoID})
}
func TestGetWatchers(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watches, err := GetWatchers(repo.ID)
assert.NoError(t, err)
// One watchers are inactive, thus minus 1
@ -52,7 +52,7 @@ func TestGetWatchers(t *testing.T) {
assert.EqualValues(t, repo.ID, watch.RepoID)
}
watches, err = GetWatchers(db.NonexistentID)
watches, err = GetWatchers(unittest.NonexistentID)
assert.NoError(t, err)
assert.Len(t, watches, 0)
}
@ -60,15 +60,15 @@ func TestGetWatchers(t *testing.T) {
func TestRepository_GetWatchers(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watchers, err := repo.GetWatchers(db.ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
for _, watcher := range watchers {
db.AssertExistsAndLoadBean(t, &Watch{UserID: watcher.ID, RepoID: repo.ID})
unittest.AssertExistsAndLoadBean(t, &Watch{UserID: watcher.ID, RepoID: repo.ID})
}
repo = db.AssertExistsAndLoadBean(t, &Repository{ID: 9}).(*Repository)
repo = unittest.AssertExistsAndLoadBean(t, &Repository{ID: 9}).(*Repository)
watchers, err = repo.GetWatchers(db.ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, 0)
@ -85,25 +85,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
db.AssertExistsAndLoadBean(t, &Action{
unittest.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 8,
RepoID: action.RepoID,
OpType: action.OpType,
})
db.AssertExistsAndLoadBean(t, &Action{
unittest.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 1,
RepoID: action.RepoID,
OpType: action.OpType,
})
db.AssertExistsAndLoadBean(t, &Action{
unittest.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 4,
RepoID: action.RepoID,
OpType: action.OpType,
})
db.AssertExistsAndLoadBean(t, &Action{
unittest.AssertExistsAndLoadBean(t, &Action{
ActUserID: action.ActUserID,
UserID: 11,
RepoID: action.RepoID,
@ -114,7 +114,7 @@ func TestNotifyWatchers(t *testing.T) {
func TestWatchIfAuto(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
watchers, err := repo.GetWatchers(db.ListOptions{Page: 1})
assert.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
@ -171,20 +171,20 @@ func TestWatchIfAuto(t *testing.T) {
func TestWatchRepoMode(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeAuto))
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeAuto}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeAuto}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeNormal))
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeNormal}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeNormal}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeDont))
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeDont}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1, Mode: RepoWatchModeDont}, 1)
assert.NoError(t, WatchRepoMode(12, 1, RepoWatchModeNone))
db.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
unittest.AssertCount(t, &Watch{UserID: 12, RepoID: 1}, 0)
}