1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-29 12:58:29 +00:00

Remove incorrect "db.DefaultContext" usages (#35366)

This commit is contained in:
wxiaoguang
2025-08-28 11:52:43 +08:00
committed by GitHub
parent 7aef7ea2d4
commit 0cbaa0b662
256 changed files with 1951 additions and 2098 deletions

View File

@@ -20,7 +20,7 @@ func TestGetFeeds(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
actions, count, err := GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedUser: user,
Actor: user,
IncludePrivate: true,
@@ -34,7 +34,7 @@ func TestGetFeeds(t *testing.T) {
}
assert.Equal(t, int64(1), count)
actions, count, err = GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedUser: user,
Actor: user,
IncludePrivate: false,
@@ -52,7 +52,7 @@ func TestGetFeedsForRepos(t *testing.T) {
pubRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 8})
// private repo & no login
actions, count, err := GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedRepo: privRepo,
IncludePrivate: true,
})
@@ -61,7 +61,7 @@ func TestGetFeedsForRepos(t *testing.T) {
assert.Equal(t, int64(0), count)
// public repo & no login
actions, count, err = GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedRepo: pubRepo,
IncludePrivate: true,
})
@@ -70,7 +70,7 @@ func TestGetFeedsForRepos(t *testing.T) {
assert.Equal(t, int64(1), count)
// private repo and login
actions, count, err = GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedRepo: privRepo,
IncludePrivate: true,
Actor: user,
@@ -80,7 +80,7 @@ func TestGetFeedsForRepos(t *testing.T) {
assert.Equal(t, int64(1), count)
// public repo & login
actions, count, err = GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedRepo: pubRepo,
IncludePrivate: true,
Actor: user,
@@ -96,7 +96,7 @@ func TestGetFeeds2(t *testing.T) {
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
actions, count, err := GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedUser: org,
Actor: user,
IncludePrivate: true,
@@ -111,7 +111,7 @@ func TestGetFeeds2(t *testing.T) {
}
assert.Equal(t, int64(1), count)
actions, count, err = GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err = GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedUser: org,
Actor: user,
IncludePrivate: false,
@@ -133,7 +133,7 @@ func TestGetFeedsCorrupted(t *testing.T) {
RepoID: 1700,
})
actions, count, err := GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, count, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedUser: user,
Actor: user,
IncludePrivate: true,
@@ -146,18 +146,18 @@ func TestGetFeedsCorrupted(t *testing.T) {
func TestRepoActions(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
_ = db.TruncateBeans(db.DefaultContext, &activities_model.Action{})
_ = db.TruncateBeans(t.Context(), &activities_model.Action{})
for i := range 3 {
_ = db.Insert(db.DefaultContext, &activities_model.Action{
_ = db.Insert(t.Context(), &activities_model.Action{
UserID: 2 + int64(i),
ActUserID: 2,
RepoID: repo.ID,
OpType: activities_model.ActionCommentIssue,
})
}
count, _ := db.Count[activities_model.Action](db.DefaultContext, &db.ListOptions{})
count, _ := db.Count[activities_model.Action](t.Context(), &db.ListOptions{})
assert.EqualValues(t, 3, count)
actions, _, err := GetFeeds(db.DefaultContext, activities_model.GetFeedsOptions{
actions, _, err := GetFeeds(t.Context(), activities_model.GetFeedsOptions{
RequestedRepo: repo,
})
assert.NoError(t, err)
@@ -172,7 +172,7 @@ func TestNotifyWatchers(t *testing.T) {
RepoID: 1,
OpType: activities_model.ActionStarRepo,
}
assert.NoError(t, NotifyWatchers(db.DefaultContext, action))
assert.NoError(t, NotifyWatchers(t.Context(), action))
// One watchers are inactive, thus action is only created for user 8, 1, 4, 11
unittest.AssertExistsAndLoadBean(t, &activities_model.Action{

View File

@@ -8,7 +8,6 @@ import (
"testing"
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -46,7 +45,7 @@ func TestRenameRepoAction(t *testing.T) {
}
unittest.AssertNotExistsBean(t, actionBean)
NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
NewNotifier().RenameRepository(t.Context(), user, repo, oldRepoName)
unittest.AssertExistsAndLoadBean(t, actionBean)
unittest.CheckConsistencyFor(t, &activities_model.Action{})