summaryrefslogtreecommitdiffstats
path: root/models/repo
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2024-07-30 21:41:10 +0200
committerEarl Warren <earl-warren@noreply.codeberg.org>2024-07-30 21:41:10 +0200
commit4de909747bdf322bbb37d500b9705d7a3a050b78 (patch)
tree62dad5d457c227628877d235f0105db9ae4bc200 /models/repo
parentMerge pull request 'Implement external release assets' (#1445) from maltejur/... (diff)
downloadforgejo-4de909747bdf322bbb37d500b9705d7a3a050b78.tar.xz
forgejo-4de909747bdf322bbb37d500b9705d7a3a050b78.zip
Add testifylint to lint checks (#4535)
go-require lint is ignored for now Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4535 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
Diffstat (limited to 'models/repo')
-rw-r--r--models/repo/archive_download_count_test.go2
-rw-r--r--models/repo/attachment_test.go39
-rw-r--r--models/repo/collaboration_test.go57
-rw-r--r--models/repo/fork_test.go11
-rw-r--r--models/repo/pushmirror_test.go3
-rw-r--r--models/repo/redirect_test.go17
-rw-r--r--models/repo/release_test.go6
-rw-r--r--models/repo/repo_flags_test.go29
-rw-r--r--models/repo/repo_list_test.go27
-rw-r--r--models/repo/repo_test.go51
-rw-r--r--models/repo/repo_unit_test.go8
-rw-r--r--models/repo/star_test.go33
-rw-r--r--models/repo/topic_test.go23
-rw-r--r--models/repo/user_repo_test.go33
-rw-r--r--models/repo/watch_test.go65
-rw-r--r--models/repo/wiki_test.go7
16 files changed, 212 insertions, 199 deletions
diff --git a/models/repo/archive_download_count_test.go b/models/repo/archive_download_count_test.go
index 53bdf9a1e0..ffc6cdf6df 100644
--- a/models/repo/archive_download_count_test.go
+++ b/models/repo/archive_download_count_test.go
@@ -16,7 +16,7 @@ import (
)
func TestRepoArchiveDownloadCount(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
release, err := repo_model.GetReleaseByID(db.DefaultContext, 1)
require.NoError(t, err)
diff --git a/models/repo/attachment_test.go b/models/repo/attachment_test.go
index c059ffd39a..23945ba1d3 100644
--- a/models/repo/attachment_test.go
+++ b/models/repo/attachment_test.go
@@ -11,62 +11,63 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestIncreaseDownloadCount(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(0), attachment.DownloadCount)
// increase download count
err = attachment.IncreaseDownloadCount(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
attachment, err = repo_model.GetAttachmentByUUID(db.DefaultContext, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(1), attachment.DownloadCount)
}
func TestGetByCommentOrIssueID(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// count of attachments from issue ID
attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, attachments, 1)
attachments, err = repo_model.GetAttachmentsByCommentID(db.DefaultContext, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, attachments, 2)
}
func TestDeleteAttachments(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
count, err := repo_model.DeleteAttachmentsByIssue(db.DefaultContext, 4, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, 2, count)
count, err = repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, 2, count)
err = repo_model.DeleteAttachment(db.DefaultContext, &repo_model.Attachment{ID: 8}, false)
- assert.NoError(t, err)
+ require.NoError(t, err)
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18")
- assert.Error(t, err)
+ require.Error(t, err)
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
assert.Nil(t, attachment)
}
func TestGetAttachmentByID(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
attach, err := repo_model.GetAttachmentByID(db.DefaultContext, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.UUID)
}
@@ -79,23 +80,23 @@ func TestAttachment_DownloadURL(t *testing.T) {
}
func TestUpdateAttachment(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
attach, err := repo_model.GetAttachmentByID(db.DefaultContext, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.UUID)
attach.Name = "new_name"
- assert.NoError(t, repo_model.UpdateAttachment(db.DefaultContext, attach))
+ require.NoError(t, repo_model.UpdateAttachment(db.DefaultContext, attach))
unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{Name: "new_name"})
}
func TestGetAttachmentsByUUIDs(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
attachList, err := repo_model.GetAttachmentsByUUIDs(db.DefaultContext, []string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, attachList, 2)
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attachList[0].UUID)
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", attachList[1].UUID)
diff --git a/models/repo/collaboration_test.go b/models/repo/collaboration_test.go
index 0bfe60801c..5adedfe442 100644
--- a/models/repo/collaboration_test.go
+++ b/models/repo/collaboration_test.go
@@ -14,16 +14,17 @@ import (
user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepository_GetCollaborators(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
test := func(repoID int64) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
collaborators, err := repo_model.GetCollaborators(db.DefaultContext, repo.ID, db.ListOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
expectedLen, err := db.GetEngine(db.DefaultContext).Count(&repo_model.Collaboration{RepoID: repoID})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, collaborators, int(expectedLen))
for _, collaborator := range collaborators {
assert.EqualValues(t, collaborator.User.ID, collaborator.Collaboration.UserID)
@@ -39,23 +40,23 @@ func TestRepository_GetCollaborators(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 22})
collaborators1, err := repo_model.GetCollaborators(db.DefaultContext, repo.ID, db.ListOptions{PageSize: 1, Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, collaborators1, 1)
collaborators2, err := repo_model.GetCollaborators(db.DefaultContext, repo.ID, db.ListOptions{PageSize: 1, Page: 2})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, collaborators2, 1)
assert.NotEqualValues(t, collaborators1[0].ID, collaborators2[0].ID)
}
func TestRepository_IsCollaborator(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
test := func(repoID, userID int64, expected bool) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
actual, err := repo_model.IsCollaborator(db.DefaultContext, repo.ID, userID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, expected, actual)
}
test(3, 2, true)
@@ -65,10 +66,10 @@ func TestRepository_IsCollaborator(t *testing.T) {
}
func TestRepository_ChangeCollaborationAccessMode(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
- assert.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessModeAdmin))
+ require.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessModeAdmin))
collaboration := unittest.AssertExistsAndLoadBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: 4})
assert.EqualValues(t, perm.AccessModeAdmin, collaboration.Mode)
@@ -76,109 +77,109 @@ func TestRepository_ChangeCollaborationAccessMode(t *testing.T) {
access := unittest.AssertExistsAndLoadBean(t, &access_model.Access{UserID: 4, RepoID: repo.ID})
assert.EqualValues(t, perm.AccessModeAdmin, access.Mode)
- assert.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessModeAdmin))
+ require.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessModeAdmin))
- assert.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, unittest.NonexistentID, perm.AccessModeAdmin))
+ require.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, unittest.NonexistentID, perm.AccessModeAdmin))
// Disvard invalid input.
- assert.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessMode(unittest.NonexistentID)))
+ require.NoError(t, repo_model.ChangeCollaborationAccessMode(db.DefaultContext, repo, 4, perm.AccessMode(unittest.NonexistentID)))
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repo.ID})
}
func TestRepository_CountCollaborators(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
count, err := db.Count[repo_model.Collaboration](db.DefaultContext, repo_model.FindCollaborationOptions{
RepoID: repo1.ID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 2, count)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 22})
count, err = db.Count[repo_model.Collaboration](db.DefaultContext, repo_model.FindCollaborationOptions{
RepoID: repo2.ID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 2, count)
// Non-existent repository.
count, err = db.Count[repo_model.Collaboration](db.DefaultContext, repo_model.FindCollaborationOptions{
RepoID: unittest.NonexistentID,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 0, count)
}
func TestRepository_IsOwnerMemberCollaborator(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
// Organisation owner.
actual, err := repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, actual)
// Team member.
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 4)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, actual)
// Normal user.
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, actual)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
// Collaborator.
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo2, 4)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, actual)
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15})
// Repository owner.
actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo3, 2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.True(t, actual)
}
func TestRepo_GetCollaboration(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
// Existing collaboration.
collab, err := repo_model.GetCollaboration(db.DefaultContext, repo.ID, 4)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, collab)
assert.EqualValues(t, 4, collab.UserID)
assert.EqualValues(t, 4, collab.RepoID)
// Non-existing collaboration.
collab, err = repo_model.GetCollaboration(db.DefaultContext, repo.ID, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, collab)
}
func TestGetCollaboratorWithUser(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
user16 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 16})
user15 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 15})
user18 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18})
collabs, err := repo_model.GetCollaboratorWithUser(db.DefaultContext, user16.ID, user15.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, collabs, 2)
assert.EqualValues(t, 5, collabs[0])
assert.EqualValues(t, 7, collabs[1])
collabs, err = repo_model.GetCollaboratorWithUser(db.DefaultContext, user16.ID, user18.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, collabs, 2)
assert.EqualValues(t, 6, collabs[0])
assert.EqualValues(t, 8, collabs[1])
diff --git a/models/repo/fork_test.go b/models/repo/fork_test.go
index e8dca204cc..dd12429cc4 100644
--- a/models/repo/fork_test.go
+++ b/models/repo/fork_test.go
@@ -11,23 +11,24 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestGetUserFork(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// User13 has repo 11 forked from repo10
repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 10)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, repo)
repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, repo)
repo, err = repo_model.GetRepositoryByID(db.DefaultContext, 9)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.NotNil(t, repo)
repo, err = repo_model.GetUserFork(db.DefaultContext, repo.ID, 13)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Nil(t, repo)
}
diff --git a/models/repo/pushmirror_test.go b/models/repo/pushmirror_test.go
index e19749d93a..ebaa6e53ba 100644
--- a/models/repo/pushmirror_test.go
+++ b/models/repo/pushmirror_test.go
@@ -13,10 +13,11 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestPushMirrorsIterate(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
now := timeutil.TimeStampNow()
diff --git a/models/repo/redirect_test.go b/models/repo/redirect_test.go
index 24cf7e89fb..2016784aed 100644
--- a/models/repo/redirect_test.go
+++ b/models/repo/redirect_test.go
@@ -11,13 +11,14 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestLookupRedirect(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repoID, err := repo_model.LookupRedirect(db.DefaultContext, 2, "oldrepo1")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, repoID)
_, err = repo_model.LookupRedirect(db.DefaultContext, unittest.NonexistentID, "doesnotexist")
@@ -26,10 +27,10 @@ func TestLookupRedirect(t *testing.T) {
func TestNewRedirect(t *testing.T) {
// redirect to a completely new name
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- assert.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
+ require.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
unittest.AssertExistsAndLoadBean(t, &repo_model.Redirect{
OwnerID: repo.OwnerID,
@@ -45,10 +46,10 @@ func TestNewRedirect(t *testing.T) {
func TestNewRedirect2(t *testing.T) {
// redirect to previously used name
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- assert.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "oldrepo1"))
+ require.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "oldrepo1"))
unittest.AssertExistsAndLoadBean(t, &repo_model.Redirect{
OwnerID: repo.OwnerID,
@@ -64,10 +65,10 @@ func TestNewRedirect2(t *testing.T) {
func TestNewRedirect3(t *testing.T) {
// redirect for a previously-unredirected repo
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
- assert.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
+ require.NoError(t, repo_model.NewRedirect(db.DefaultContext, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
unittest.AssertExistsAndLoadBean(t, &repo_model.Redirect{
OwnerID: repo.OwnerID,
diff --git a/models/repo/release_test.go b/models/repo/release_test.go
index 3643bff7f1..4e61a2805d 100644
--- a/models/repo/release_test.go
+++ b/models/repo/release_test.go
@@ -9,11 +9,11 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestMigrate_InsertReleases(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
a := &Attachment{
UUID: "a0eebc91-9c0c-4ef7-bb6e-6bb9bd380a12",
@@ -23,5 +23,5 @@ func TestMigrate_InsertReleases(t *testing.T) {
}
err := InsertReleases(db.DefaultContext, r)
- assert.NoError(t, err)
+ require.NoError(t, err)
}
diff --git a/models/repo/repo_flags_test.go b/models/repo/repo_flags_test.go
index 0e4f5c1ba9..bccefcf72b 100644
--- a/models/repo/repo_flags_test.go
+++ b/models/repo/repo_flags_test.go
@@ -11,10 +11,11 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepositoryFlags(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
// ********************
@@ -23,7 +24,7 @@ func TestRepositoryFlags(t *testing.T) {
// Unless we add flags, the repo has none
flags, err := repo.ListFlags(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, flags)
// If the repo has no flags, it is not flagged
@@ -36,12 +37,12 @@ func TestRepositoryFlags(t *testing.T) {
// Trying to retrieve a non-existent flag indicates not found
has, _, err = repo.GetFlag(db.DefaultContext, "foo")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.False(t, has)
// Deleting a non-existent flag fails
deleted, err := repo.DeleteFlag(db.DefaultContext, "no-such-flag")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(0), deleted)
// ********************
@@ -50,15 +51,15 @@ func TestRepositoryFlags(t *testing.T) {
// Adding a flag works
err = repo.AddFlag(db.DefaultContext, "foo")
- assert.NoError(t, err)
+ require.NoError(t, err)
// Adding it again fails
err = repo.AddFlag(db.DefaultContext, "foo")
- assert.Error(t, err)
+ require.Error(t, err)
// Listing flags includes the one we added
flags, err = repo.ListFlags(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, flags, 1)
assert.Equal(t, "foo", flags[0].Name)
@@ -72,22 +73,22 @@ func TestRepositoryFlags(t *testing.T) {
// Added flag can be retrieved
_, flag, err := repo.GetFlag(db.DefaultContext, "foo")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, "foo", flag.Name)
// Deleting a flag works
deleted, err = repo.DeleteFlag(db.DefaultContext, "foo")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(1), deleted)
// The list is now empty
flags, err = repo.ListFlags(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, flags)
// Replacing an empty list works
err = repo.ReplaceAllFlags(db.DefaultContext, []string{"bar"})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo is now flagged with "bar"
has = repo.HasFlag(db.DefaultContext, "bar")
@@ -95,18 +96,18 @@ func TestRepositoryFlags(t *testing.T) {
// Replacing a tag set with another works
err = repo.ReplaceAllFlags(db.DefaultContext, []string{"baz", "quux"})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo now has two tags
flags, err = repo.ListFlags(db.DefaultContext)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, flags, 2)
assert.Equal(t, "baz", flags[0].Name)
assert.Equal(t, "quux", flags[1].Name)
// Replacing flags with an empty set deletes all flags
err = repo.ReplaceAllFlags(db.DefaultContext, []string{})
- assert.NoError(t, err)
+ require.NoError(t, err)
// The repo is now unflagged
flagged = repo.IsFlagged(db.DefaultContext)
diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go
index 6b1bb39b85..b31aa1780f 100644
--- a/models/repo/repo_list_test.go
+++ b/models/repo/repo_list_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/optional"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func getTestCases() []struct {
@@ -181,7 +182,7 @@ func getTestCases() []struct {
}
func TestSearchRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// test search public repository on explore page
repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{
@@ -193,7 +194,7 @@ func TestSearchRepository(t *testing.T) {
Collaborate: optional.Some(false),
})
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, repos, 1) {
assert.Equal(t, "test_repo_12", repos[0].Name)
}
@@ -208,7 +209,7 @@ func TestSearchRepository(t *testing.T) {
Collaborate: optional.Some(false),
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(2), count)
assert.Len(t, repos, 2)
@@ -223,7 +224,7 @@ func TestSearchRepository(t *testing.T) {
Collaborate: optional.Some(false),
})
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, repos, 1) {
assert.Equal(t, "test_repo_13", repos[0].Name)
}
@@ -239,14 +240,14 @@ func TestSearchRepository(t *testing.T) {
Collaborate: optional.Some(false),
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(3), count)
assert.Len(t, repos, 3)
// Test non existing owner
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{OwnerID: unittest.NonexistentID})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, repos)
assert.Equal(t, int64(0), count)
@@ -261,7 +262,7 @@ func TestSearchRepository(t *testing.T) {
IncludeDescription: true,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, repos, 1) {
assert.Equal(t, "test_repo_14", repos[0].Name)
}
@@ -278,7 +279,7 @@ func TestSearchRepository(t *testing.T) {
IncludeDescription: false,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Empty(t, repos)
assert.Equal(t, int64(0), count)
@@ -288,7 +289,7 @@ func TestSearchRepository(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, testCase.opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(testCase.count), count)
page := testCase.opts.Page
@@ -355,7 +356,7 @@ func TestSearchRepository(t *testing.T) {
}
func TestCountRepository(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
testCases := getTestCases()
@@ -363,14 +364,14 @@ func TestCountRepository(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
count, err := repo_model.CountRepository(db.DefaultContext, testCase.opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(testCase.count), count)
})
}
}
func TestSearchRepositoryByTopicName(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
testCases := []struct {
name string
@@ -397,7 +398,7 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
_, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, testCase.opts)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(testCase.count), count)
})
}
diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go
index a279478177..56b84798d7 100644
--- a/models/repo/repo_test.go
+++ b/models/repo/repo_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var (
@@ -27,58 +28,58 @@ var (
)
func TestGetRepositoryCount(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
ctx := db.DefaultContext
count, err1 := repo_model.CountRepositories(ctx, countRepospts)
privateCount, err2 := repo_model.CountRepositories(ctx, countReposptsPrivate)
publicCount, err3 := repo_model.CountRepositories(ctx, countReposptsPublic)
- assert.NoError(t, err1)
- assert.NoError(t, err2)
- assert.NoError(t, err3)
+ require.NoError(t, err1)
+ require.NoError(t, err2)
+ require.NoError(t, err3)
assert.Equal(t, int64(3), count)
assert.Equal(t, privateCount+publicCount, count)
}
func TestGetPublicRepositoryCount(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
count, err := repo_model.CountRepositories(db.DefaultContext, countReposptsPublic)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(1), count)
}
func TestGetPrivateRepositoryCount(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
count, err := repo_model.CountRepositories(db.DefaultContext, countReposptsPrivate)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Equal(t, int64(2), count)
}
func TestRepoAPIURL(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
}
func TestWatchRepo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
const repoID = 3
const userID = 2
- assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, true))
+ require.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, true))
unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
- assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, false))
+ require.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, false))
unittest.AssertNotExistsBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
}
func TestMetas(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := &repo_model.Repository{Name: "testRepo"}
repo.Owner = &user_model.User{Name: "testOwner"}
@@ -119,7 +120,7 @@ func TestMetas(t *testing.T) {
testSuccess(markup.IssueNameStyleRegexp)
repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 3)
- assert.NoError(t, err)
+ require.NoError(t, err)
metas = repo.ComposeMetas(db.DefaultContext)
assert.Contains(t, metas, "org")
@@ -129,13 +130,13 @@ func TestMetas(t *testing.T) {
}
func TestGetRepositoryByURL(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
t.Run("InvalidPath", func(t *testing.T) {
repo, err := repo_model.GetRepositoryByURL(db.DefaultContext, "something")
assert.Nil(t, repo)
- assert.Error(t, err)
+ require.Error(t, err)
})
t.Run("ValidHttpURL", func(t *testing.T) {
@@ -143,10 +144,10 @@ func TestGetRepositoryByURL(t *testing.T) {
repo, err := repo_model.GetRepositoryByURL(db.DefaultContext, url)
assert.NotNil(t, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.Equal(t, repo.ID, int64(2))
- assert.Equal(t, repo.OwnerID, int64(2))
+ assert.Equal(t, int64(2), repo.ID)
+ assert.Equal(t, int64(2), repo.OwnerID)
}
test(t, "https://try.gitea.io/user2/repo2")
@@ -158,10 +159,10 @@ func TestGetRepositoryByURL(t *testing.T) {
repo, err := repo_model.GetRepositoryByURL(db.DefaultContext, url)
assert.NotNil(t, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.Equal(t, repo.ID, int64(2))
- assert.Equal(t, repo.OwnerID, int64(2))
+ assert.Equal(t, int64(2), repo.ID)
+ assert.Equal(t, int64(2), repo.OwnerID)
}
test(t, "git+ssh://sshuser@try.gitea.io/user2/repo2")
@@ -176,10 +177,10 @@ func TestGetRepositoryByURL(t *testing.T) {
repo, err := repo_model.GetRepositoryByURL(db.DefaultContext, url)
assert.NotNil(t, repo)
- assert.NoError(t, err)
+ require.NoError(t, err)
- assert.Equal(t, repo.ID, int64(2))
- assert.Equal(t, repo.OwnerID, int64(2))
+ assert.Equal(t, int64(2), repo.ID)
+ assert.Equal(t, int64(2), repo.OwnerID)
}
test(t, "sshuser@try.gitea.io:user2/repo2")
diff --git a/models/repo/repo_unit_test.go b/models/repo/repo_unit_test.go
index 27a34fd0eb..deee1a7472 100644
--- a/models/repo/repo_unit_test.go
+++ b/models/repo/repo_unit_test.go
@@ -32,8 +32,8 @@ func TestActionsConfig(t *testing.T) {
}
func TestRepoUnitAccessMode(t *testing.T) {
- assert.Equal(t, UnitAccessModeNone.ToAccessMode(perm.AccessModeAdmin), perm.AccessModeNone)
- assert.Equal(t, UnitAccessModeRead.ToAccessMode(perm.AccessModeAdmin), perm.AccessModeRead)
- assert.Equal(t, UnitAccessModeWrite.ToAccessMode(perm.AccessModeAdmin), perm.AccessModeWrite)
- assert.Equal(t, UnitAccessModeUnset.ToAccessMode(perm.AccessModeRead), perm.AccessModeRead)
+ assert.Equal(t, perm.AccessModeNone, UnitAccessModeNone.ToAccessMode(perm.AccessModeAdmin))
+ assert.Equal(t, perm.AccessModeRead, UnitAccessModeRead.ToAccessMode(perm.AccessModeAdmin))
+ assert.Equal(t, perm.AccessModeWrite, UnitAccessModeWrite.ToAccessMode(perm.AccessModeAdmin))
+ assert.Equal(t, perm.AccessModeRead, UnitAccessModeUnset.ToAccessMode(perm.AccessModeRead))
}
diff --git a/models/repo/star_test.go b/models/repo/star_test.go
index 62eac4e29a..73b362c68c 100644
--- a/models/repo/star_test.go
+++ b/models/repo/star_test.go
@@ -11,33 +11,34 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestStarRepo(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
const userID = 2
const repoID = 1
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
+ require.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
unittest.AssertExistsAndLoadBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
+ require.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
unittest.AssertExistsAndLoadBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, false))
+ require.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, false))
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
}
func TestIsStaring(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
assert.True(t, repo_model.IsStaring(db.DefaultContext, 2, 4))
assert.False(t, repo_model.IsStaring(db.DefaultContext, 3, 4))
}
func TestRepository_GetStargazers(t *testing.T) {
// repo with stargazers
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, gazers, 1) {
assert.Equal(t, int64(2), gazers[0].ID)
}
@@ -45,27 +46,27 @@ func TestRepository_GetStargazers(t *testing.T) {
func TestRepository_GetStargazers2(t *testing.T) {
// repo with stargazers
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
- assert.NoError(t, err)
- assert.Len(t, gazers, 0)
+ require.NoError(t, err)
+ assert.Empty(t, gazers)
}
func TestClearRepoStars(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
const userID = 2
const repoID = 1
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
+ require.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, true))
unittest.AssertExistsAndLoadBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, false))
+ require.NoError(t, repo_model.StarRepo(db.DefaultContext, userID, repoID, false))
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
- assert.NoError(t, repo_model.ClearRepoStars(db.DefaultContext, repoID))
+ require.NoError(t, repo_model.ClearRepoStars(db.DefaultContext, repoID))
unittest.AssertNotExistsBean(t, &repo_model.Star{UID: userID, RepoID: repoID})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
- assert.NoError(t, err)
- assert.Len(t, gazers, 0)
+ require.NoError(t, err)
+ assert.Empty(t, gazers)
}
diff --git a/models/repo/topic_test.go b/models/repo/topic_test.go
index 2b609e6d66..45cee524b6 100644
--- a/models/repo/topic_test.go
+++ b/models/repo/topic_test.go
@@ -11,58 +11,59 @@ import (
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAddTopic(t *testing.T) {
totalNrOfTopics := 6
repo1NrOfTopics := 3
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
topics, _, err := repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, totalNrOfTopics)
topics, total, err := repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{
ListOptions: db.ListOptions{Page: 1, PageSize: 2},
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, 2)
assert.EqualValues(t, 6, total)
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{
RepoID: 1,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, repo1NrOfTopics)
- assert.NoError(t, repo_model.SaveTopics(db.DefaultContext, 2, "golang"))
+ require.NoError(t, repo_model.SaveTopics(db.DefaultContext, 2, "golang"))
repo2NrOfTopics := 1
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, totalNrOfTopics)
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{
RepoID: 2,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, repo2NrOfTopics)
- assert.NoError(t, repo_model.SaveTopics(db.DefaultContext, 2, "golang", "gitea"))
+ require.NoError(t, repo_model.SaveTopics(db.DefaultContext, 2, "golang", "gitea"))
repo2NrOfTopics = 2
totalNrOfTopics++
topic, err := repo_model.GetTopicByName(db.DefaultContext, "gitea")
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.EqualValues(t, 1, topic.RepoCount)
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, totalNrOfTopics)
topics, _, err = repo_model.FindTopics(db.DefaultContext, &repo_model.FindTopicOptions{
RepoID: 2,
})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, topics, repo2NrOfTopics)
}
diff --git a/models/repo/user_repo_test.go b/models/repo/user_repo_test.go
index 0433ff83d8..c784a5565d 100644
--- a/models/repo/user_repo_test.go
+++ b/models/repo/user_repo_test.go
@@ -12,84 +12,85 @@ import (
user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepoAssignees(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
users, err := repo_model.GetRepoAssignees(db.DefaultContext, repo2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, users, 1)
- assert.Equal(t, users[0].ID, int64(2))
+ assert.Equal(t, int64(2), users[0].ID)
repo21 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21})
users, err = repo_model.GetRepoAssignees(db.DefaultContext, repo21)
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, users, 3) {
assert.ElementsMatch(t, []int64{15, 16, 18}, []int64{users[0].ID, users[1].ID, users[2].ID})
}
// do not return deactivated users
- assert.NoError(t, user_model.UpdateUserCols(db.DefaultContext, &user_model.User{ID: 15, IsActive: false}, "is_active"))
+ require.NoError(t, user_model.UpdateUserCols(db.DefaultContext, &user_model.User{ID: 15, IsActive: false}, "is_active"))
users, err = repo_model.GetRepoAssignees(db.DefaultContext, repo21)
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, users, 2) {
assert.NotContains(t, []int64{users[0].ID, users[1].ID}, 15)
}
}
func TestRepoGetReviewers(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
// test public repo
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
ctx := db.DefaultContext
reviewers, err := repo_model.GetReviewers(ctx, repo1, 2, 2)
- assert.NoError(t, err)
+ require.NoError(t, err)
if assert.Len(t, reviewers, 3) {
assert.ElementsMatch(t, []int64{1, 4, 11}, []int64{reviewers[0].ID, reviewers[1].ID, reviewers[2].ID})
}
// should include doer if doer is not PR poster.
reviewers, err = repo_model.GetReviewers(ctx, repo1, 11, 2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, reviewers, 3)
// should not include PR poster, if PR poster would be otherwise eligible
reviewers, err = repo_model.GetReviewers(ctx, repo1, 11, 4)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, reviewers, 2)
// test private user repo
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
reviewers, err = repo_model.GetReviewers(ctx, repo2, 2, 4)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, reviewers, 1)
- assert.EqualValues(t, reviewers[0].ID, 2)
+ assert.EqualValues(t, 2, reviewers[0].ID)
// test private org repo
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
reviewers, err = repo_model.GetReviewers(ctx, repo3, 2, 1)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, reviewers, 2)
reviewers, err = repo_model.GetReviewers(ctx, repo3, 2, 2)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, reviewers, 1)
}
func GetWatchedRepoIDsOwnedBy(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 9})
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
repoIDs, err := repo_model.GetWatchedRepoIDsOwnedBy(db.DefaultContext, user1.ID, user2.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, repoIDs, 1)
assert.EqualValues(t, 1, repoIDs[0])
}
diff --git a/models/repo/watch_test.go b/models/repo/watch_test.go
index 4dd9234f3b..dbf15050cf 100644
--- a/models/repo/watch_test.go
+++ b/models/repo/watch_test.go
@@ -12,10 +12,11 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestIsWatching(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
assert.True(t, repo_model.IsWatching(db.DefaultContext, 1, 1))
assert.True(t, repo_model.IsWatching(db.DefaultContext, 4, 1))
@@ -27,11 +28,11 @@ func TestIsWatching(t *testing.T) {
}
func TestGetWatchers(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
watches, err := repo_model.GetWatchers(db.DefaultContext, repo.ID)
- assert.NoError(t, err)
+ require.NoError(t, err)
// One watchers are inactive, thus minus 1
assert.Len(t, watches, repo.NumWatches-1)
for _, watch := range watches {
@@ -39,16 +40,16 @@ func TestGetWatchers(t *testing.T) {
}
watches, err = repo_model.GetWatchers(db.DefaultContext, unittest.NonexistentID)
- assert.NoError(t, err)
- assert.Len(t, watches, 0)
+ require.NoError(t, err)
+ assert.Empty(t, watches)
}
func TestRepository_GetWatchers(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
watchers, err := repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
for _, watcher := range watchers {
unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{UserID: watcher.ID, RepoID: repo.ID})
@@ -56,16 +57,16 @@ func TestRepository_GetWatchers(t *testing.T) {
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 9})
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
- assert.Len(t, watchers, 0)
+ require.NoError(t, err)
+ assert.Empty(t, watchers)
}
func TestWatchIfAuto(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
watchers, err := repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, repo.NumWatches)
setting.Service.AutoWatchOnChanges = false
@@ -73,79 +74,79 @@ func TestWatchIfAuto(t *testing.T) {
prevCount := repo.NumWatches
// Must not add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 8, 1, true))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 8, 1, true))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
// Should not add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 10, 1, true))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 10, 1, true))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
setting.Service.AutoWatchOnChanges = true
// Must not add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 8, 1, true))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 8, 1, true))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
// Should not add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, false))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, false))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
// Should add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, true))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, true))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount+1)
// Should remove watch, inhibit from adding auto
- assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, 12, 1, false))
+ require.NoError(t, repo_model.WatchRepo(db.DefaultContext, 12, 1, false))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
// Must not add watch
- assert.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, true))
+ require.NoError(t, repo_model.WatchIfAuto(db.DefaultContext, 12, 1, true))
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
- assert.NoError(t, err)
+ require.NoError(t, err)
assert.Len(t, watchers, prevCount)
}
func TestWatchRepoMode(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
- assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeAuto))
+ require.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeAuto))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeAuto}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNormal))
+ require.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNormal))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeNormal}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeDont))
+ require.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeDont))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 1)
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1, Mode: repo_model.WatchModeDont}, 1)
- assert.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNone))
+ require.NoError(t, repo_model.WatchRepoMode(db.DefaultContext, 12, 1, repo_model.WatchModeNone))
unittest.AssertCount(t, &repo_model.Watch{UserID: 12, RepoID: 1}, 0)
}
func TestUnwatchRepos(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{UserID: 4, RepoID: 1})
unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{UserID: 4, RepoID: 2})
err := repo_model.UnwatchRepos(db.DefaultContext, 4, []int64{1, 2})
- assert.NoError(t, err)
+ require.NoError(t, err)
unittest.AssertNotExistsBean(t, &repo_model.Watch{UserID: 4, RepoID: 1})
unittest.AssertNotExistsBean(t, &repo_model.Watch{UserID: 4, RepoID: 2})
diff --git a/models/repo/wiki_test.go b/models/repo/wiki_test.go
index 629986f741..28495a4b7d 100644
--- a/models/repo/wiki_test.go
+++ b/models/repo/wiki_test.go
@@ -12,10 +12,11 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestRepository_WikiCloneLink(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
cloneLink := repo.WikiCloneLink()
@@ -24,13 +25,13 @@ func TestRepository_WikiCloneLink(t *testing.T) {
}
func TestWikiPath(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, repo_model.WikiPath("user2", "repo1"))
}
func TestRepository_WikiPath(t *testing.T) {
- assert.NoError(t, unittest.PrepareTestDatabase())
+ require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
expected := filepath.Join(setting.RepoRootPath, "user2/repo1.wiki.git")
assert.Equal(t, expected, repo.WikiPath())