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

@@ -6,7 +6,6 @@ package convert
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -25,27 +24,27 @@ func Test_ToPullReview(t *testing.T) {
reviewList := []*issues_model.Review{review}
t.Run("Anonymous User", func(t *testing.T) {
prList, err := ToPullReviewList(db.DefaultContext, reviewList, nil)
prList, err := ToPullReviewList(t.Context(), reviewList, nil)
assert.NoError(t, err)
assert.Empty(t, prList)
})
t.Run("Reviewer Himself", func(t *testing.T) {
prList, err := ToPullReviewList(db.DefaultContext, reviewList, reviewer)
prList, err := ToPullReviewList(t.Context(), reviewList, reviewer)
assert.NoError(t, err)
assert.Len(t, prList, 1)
})
t.Run("Other User", func(t *testing.T) {
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
prList, err := ToPullReviewList(db.DefaultContext, reviewList, user4)
prList, err := ToPullReviewList(t.Context(), reviewList, user4)
assert.NoError(t, err)
assert.Empty(t, prList)
})
t.Run("Admin User", func(t *testing.T) {
adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
prList, err := ToPullReviewList(db.DefaultContext, reviewList, adminUser)
prList, err := ToPullReviewList(t.Context(), reviewList, adminUser)
assert.NoError(t, err)
assert.Len(t, prList, 1)
})

View File

@@ -6,7 +6,6 @@ package convert
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
@@ -22,8 +21,8 @@ func TestPullRequest_APIFormat(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
assert.NoError(t, pr.LoadAttributes(t.Context()))
assert.NoError(t, pr.LoadIssue(t.Context()))
apiPullRequest := ToAPIPullRequest(t.Context(), pr, nil)
assert.NotNil(t, apiPullRequest)
assert.Equal(t, &structs.PRBranchInfo{
@@ -31,13 +30,13 @@ func TestPullRequest_APIFormat(t *testing.T) {
Ref: "refs/pull/2/head",
Sha: "4a357436d925b5c974181ff12a994538ddc5a269",
RepoID: 1,
Repository: ToRepo(db.DefaultContext, headRepo, access_model.Permission{AccessMode: perm.AccessModeRead}),
Repository: ToRepo(t.Context(), headRepo, access_model.Permission{AccessMode: perm.AccessModeRead}),
}, apiPullRequest.Head)
// withOut HeadRepo
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
assert.NoError(t, pr.LoadIssue(t.Context()))
assert.NoError(t, pr.LoadAttributes(t.Context()))
// simulate fork deletion
pr.HeadRepo = nil
pr.HeadRepoID = 100000

View File

@@ -6,7 +6,6 @@ package convert
import (
"testing"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -18,9 +17,9 @@ func TestRelease_ToRelease(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
release1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{ID: 1})
release1.LoadAttributes(db.DefaultContext)
release1.LoadAttributes(t.Context())
apiRelease := ToAPIRelease(db.DefaultContext, repo1, release1)
apiRelease := ToAPIRelease(t.Context(), repo1, release1)
assert.NotNil(t, apiRelease)
assert.EqualValues(t, 1, apiRelease.ID)
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/releases/1", apiRelease.URL)

View File

@@ -6,7 +6,6 @@ package convert
import (
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
api "code.gitea.io/gitea/modules/structs"
@@ -19,22 +18,22 @@ func TestUser_ToUser(t *testing.T) {
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true})
apiUser := toUser(db.DefaultContext, user1, true, true)
apiUser := toUser(t.Context(), user1, true, true)
assert.True(t, apiUser.IsAdmin)
assert.Contains(t, apiUser.AvatarURL, "://")
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false})
apiUser = toUser(db.DefaultContext, user2, true, true)
apiUser = toUser(t.Context(), user2, true, true)
assert.False(t, apiUser.IsAdmin)
apiUser = toUser(db.DefaultContext, user1, false, false)
apiUser = toUser(t.Context(), user1, false, false)
assert.False(t, apiUser.IsAdmin)
assert.Equal(t, api.VisibleTypePublic.String(), apiUser.Visibility)
user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate})
apiUser = toUser(db.DefaultContext, user31, true, true)
apiUser = toUser(t.Context(), user31, true, true)
assert.False(t, apiUser.IsAdmin)
assert.Equal(t, api.VisibleTypePrivate.String(), apiUser.Visibility)
}