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:
@@ -25,10 +25,10 @@ func TestInitToken(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Run("NoToken", func(t *testing.T) {
|
||||
_, _ = db.Exec(db.DefaultContext, "DELETE FROM action_runner_token")
|
||||
_, _ = db.Exec(t.Context(), "DELETE FROM action_runner_token")
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN", "")
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN_FILE", "")
|
||||
err := initGlobalRunnerToken(db.DefaultContext)
|
||||
err := initGlobalRunnerToken(t.Context())
|
||||
require.NoError(t, err)
|
||||
notEmpty, err := db.IsTableNotEmpty(&actions_model.ActionRunnerToken{})
|
||||
require.NoError(t, err)
|
||||
@@ -39,13 +39,13 @@ func TestInitToken(t *testing.T) {
|
||||
tokenValue, _ := util.CryptoRandomString(32)
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN", tokenValue)
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN_FILE", "")
|
||||
err := initGlobalRunnerToken(db.DefaultContext)
|
||||
err := initGlobalRunnerToken(t.Context())
|
||||
require.NoError(t, err)
|
||||
token := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
|
||||
assert.True(t, token.IsActive)
|
||||
|
||||
// init with the same token again, should not create a new token
|
||||
err = initGlobalRunnerToken(db.DefaultContext)
|
||||
err = initGlobalRunnerToken(t.Context())
|
||||
require.NoError(t, err)
|
||||
token2 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
|
||||
assert.Equal(t, token.ID, token2.ID)
|
||||
@@ -58,13 +58,13 @@ func TestInitToken(t *testing.T) {
|
||||
_ = os.WriteFile(f, []byte(tokenValue), 0o644)
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN", "")
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN_FILE", f)
|
||||
err := initGlobalRunnerToken(db.DefaultContext)
|
||||
err := initGlobalRunnerToken(t.Context())
|
||||
require.NoError(t, err)
|
||||
token := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
|
||||
assert.True(t, token.IsActive)
|
||||
|
||||
// if the env token is invalidated by another new token, then it shouldn't be active anymore
|
||||
_, err = actions_model.NewRunnerToken(db.DefaultContext, 0, 0)
|
||||
_, err = actions_model.NewRunnerToken(t.Context(), 0, 0)
|
||||
require.NoError(t, err)
|
||||
token = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
|
||||
assert.False(t, token.IsActive)
|
||||
@@ -72,7 +72,7 @@ func TestInitToken(t *testing.T) {
|
||||
|
||||
t.Run("InvalidToken", func(t *testing.T) {
|
||||
t.Setenv("GITEA_RUNNER_REGISTRATION_TOKEN", "abc")
|
||||
err := initGlobalRunnerToken(db.DefaultContext)
|
||||
err := initGlobalRunnerToken(t.Context())
|
||||
assert.ErrorContains(t, err, "must be at least")
|
||||
})
|
||||
}
|
||||
|
@@ -66,8 +66,8 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib
|
||||
|
||||
for i, kase := range testCases {
|
||||
s.ID = int64(i) + 20
|
||||
asymkey_model.AddPublicKeysBySource(db.DefaultContext, user, s, []string{kase.keyString})
|
||||
keys, err := db.Find[asymkey_model.PublicKey](db.DefaultContext, asymkey_model.FindPublicKeyOptions{
|
||||
asymkey_model.AddPublicKeysBySource(t.Context(), user, s, []string{kase.keyString})
|
||||
keys, err := db.Find[asymkey_model.PublicKey](t.Context(), asymkey_model.FindPublicKeyOptions{
|
||||
OwnerID: user.ID,
|
||||
LoginSourceID: s.ID,
|
||||
})
|
||||
@@ -81,7 +81,7 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib
|
||||
assert.Contains(t, kase.keyContents, key.Content)
|
||||
}
|
||||
for _, key := range keys {
|
||||
DeletePublicKey(db.DefaultContext, user, key.ID)
|
||||
DeletePublicKey(t.Context(), user, key.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
@@ -32,14 +31,14 @@ func TestUploadAttachment(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
attach, err := NewAttachment(db.DefaultContext, &repo_model.Attachment{
|
||||
attach, err := NewAttachment(t.Context(), &repo_model.Attachment{
|
||||
RepoID: 1,
|
||||
UploaderID: user.ID,
|
||||
Name: filepath.Base(fPath),
|
||||
}, f, -1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attach.UUID)
|
||||
attachment, err := repo_model.GetAttachmentByUUID(t.Context(), attach.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, user.ID, attachment.UploaderID)
|
||||
assert.Equal(t, int64(0), attachment.DownloadCount)
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
@@ -19,19 +18,19 @@ func TestCheckAuthToken(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
token, err := CheckAuthToken(db.DefaultContext, "")
|
||||
token, err := CheckAuthToken(t.Context(), "")
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, token)
|
||||
})
|
||||
|
||||
t.Run("InvalidFormat", func(t *testing.T) {
|
||||
token, err := CheckAuthToken(db.DefaultContext, "dummy")
|
||||
token, err := CheckAuthToken(t.Context(), "dummy")
|
||||
assert.ErrorIs(t, err, ErrAuthTokenInvalidFormat)
|
||||
assert.Nil(t, token)
|
||||
})
|
||||
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
token, err := CheckAuthToken(db.DefaultContext, "notexists:dummy")
|
||||
token, err := CheckAuthToken(t.Context(), "notexists:dummy")
|
||||
assert.ErrorIs(t, err, ErrAuthTokenExpired)
|
||||
assert.Nil(t, token)
|
||||
})
|
||||
@@ -39,44 +38,44 @@ func TestCheckAuthToken(t *testing.T) {
|
||||
t.Run("Expired", func(t *testing.T) {
|
||||
timeutil.MockSet(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
|
||||
at, token, err := CreateAuthTokenForUserID(db.DefaultContext, 2)
|
||||
at, token, err := CreateAuthTokenForUserID(t.Context(), 2)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at)
|
||||
assert.NotEmpty(t, token)
|
||||
|
||||
timeutil.MockUnset()
|
||||
|
||||
at2, err := CheckAuthToken(db.DefaultContext, at.ID+":"+token)
|
||||
at2, err := CheckAuthToken(t.Context(), at.ID+":"+token)
|
||||
assert.ErrorIs(t, err, ErrAuthTokenExpired)
|
||||
assert.Nil(t, at2)
|
||||
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(db.DefaultContext, at.ID))
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(t.Context(), at.ID))
|
||||
})
|
||||
|
||||
t.Run("InvalidHash", func(t *testing.T) {
|
||||
at, token, err := CreateAuthTokenForUserID(db.DefaultContext, 2)
|
||||
at, token, err := CreateAuthTokenForUserID(t.Context(), 2)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at)
|
||||
assert.NotEmpty(t, token)
|
||||
|
||||
at2, err := CheckAuthToken(db.DefaultContext, at.ID+":"+token+"dummy")
|
||||
at2, err := CheckAuthToken(t.Context(), at.ID+":"+token+"dummy")
|
||||
assert.ErrorIs(t, err, ErrAuthTokenInvalidHash)
|
||||
assert.Nil(t, at2)
|
||||
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(db.DefaultContext, at.ID))
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(t.Context(), at.ID))
|
||||
})
|
||||
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
at, token, err := CreateAuthTokenForUserID(db.DefaultContext, 2)
|
||||
at, token, err := CreateAuthTokenForUserID(t.Context(), 2)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at)
|
||||
assert.NotEmpty(t, token)
|
||||
|
||||
at2, err := CheckAuthToken(db.DefaultContext, at.ID+":"+token)
|
||||
at2, err := CheckAuthToken(t.Context(), at.ID+":"+token)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at2)
|
||||
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(db.DefaultContext, at.ID))
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(t.Context(), at.ID))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,14 +85,14 @@ func TestRegenerateAuthToken(t *testing.T) {
|
||||
timeutil.MockSet(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||
defer timeutil.MockUnset()
|
||||
|
||||
at, token, err := CreateAuthTokenForUserID(db.DefaultContext, 2)
|
||||
at, token, err := CreateAuthTokenForUserID(t.Context(), 2)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at)
|
||||
assert.NotEmpty(t, token)
|
||||
|
||||
timeutil.MockSet(time.Date(2023, 1, 1, 0, 0, 1, 0, time.UTC))
|
||||
|
||||
at2, token2, err := RegenerateAuthToken(db.DefaultContext, at)
|
||||
at2, token2, err := RegenerateAuthToken(t.Context(), at)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, at2)
|
||||
assert.NotEmpty(t, token2)
|
||||
@@ -103,5 +102,5 @@ func TestRegenerateAuthToken(t *testing.T) {
|
||||
assert.NotEqual(t, token, token2)
|
||||
assert.NotEqual(t, at.ExpiresUnix, at2.ExpiresUnix)
|
||||
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(db.DefaultContext, at.ID))
|
||||
assert.NoError(t, auth_model.DeleteAuthTokenByID(t.Context(), at.ID))
|
||||
}
|
||||
|
@@ -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)
|
||||
})
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -24,16 +24,16 @@ func TestConsistencyCheck(t *testing.T) {
|
||||
})
|
||||
require.NotEqual(t, -1, idx)
|
||||
|
||||
_ = db.TruncateBeans(db.DefaultContext, &auth.OAuth2Application{}, &user.User{})
|
||||
_ = db.TruncateBeans(db.DefaultContext, &auth.OAuth2Application{}, &auth.OAuth2Application{})
|
||||
_ = db.TruncateBeans(t.Context(), &auth.OAuth2Application{}, &user.User{})
|
||||
_ = db.TruncateBeans(t.Context(), &auth.OAuth2Application{}, &auth.OAuth2Application{})
|
||||
|
||||
err := db.Insert(db.DefaultContext, &user.User{ID: 1})
|
||||
err := db.Insert(t.Context(), &user.User{ID: 1})
|
||||
assert.NoError(t, err)
|
||||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-1", ClientID: "client-id-1"})
|
||||
err = db.Insert(t.Context(), &auth.OAuth2Application{Name: "test-oauth2-app-1", ClientID: "client-id-1"})
|
||||
assert.NoError(t, err)
|
||||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-2", ClientID: "client-id-2", UID: 1})
|
||||
err = db.Insert(t.Context(), &auth.OAuth2Application{Name: "test-oauth2-app-2", ClientID: "client-id-2", UID: 1})
|
||||
assert.NoError(t, err)
|
||||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-3", ClientID: "client-id-3", UID: 99999999})
|
||||
err = db.Insert(t.Context(), &auth.OAuth2Application{Name: "test-oauth2-app-3", ClientID: "client-id-3", UID: 99999999})
|
||||
assert.NoError(t, err)
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-1"})
|
||||
@@ -41,7 +41,7 @@ func TestConsistencyCheck(t *testing.T) {
|
||||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-3"})
|
||||
|
||||
oauth2AppCheck := checks[idx]
|
||||
err = oauth2AppCheck.Run(db.DefaultContext, log.GetManager().GetLogger(log.DEFAULT), true)
|
||||
err = oauth2AppCheck.Run(t.Context(), log.GetManager().GetLogger(log.DEFAULT), true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-1"})
|
||||
|
@@ -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{
|
||||
|
@@ -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{})
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
csv_module "code.gitea.io/gitea/modules/csv"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
@@ -191,7 +190,7 @@ c,d,e`,
|
||||
}
|
||||
|
||||
for n, c := range cases {
|
||||
diff, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.diff), "")
|
||||
diff, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.diff), "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
var baseReader *csv.Reader
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -210,7 +209,7 @@ func TestGitDiffTree(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
diffPaths, err := GetDiffTree(db.DefaultContext, gitRepo, tt.useMergeBase, tt.BaseSha, tt.HeadSha)
|
||||
diffPaths, err := GetDiffTree(t.Context(), gitRepo, tt.useMergeBase, tt.BaseSha, tt.HeadSha)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, tt.Expected, diffPaths)
|
||||
@@ -419,7 +418,7 @@ func TestGitDiffTreeErrors(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
diffPaths, err := GetDiffTree(db.DefaultContext, gitRepo, true, tt.BaseSha, tt.HeadSha)
|
||||
diffPaths, err := GetDiffTree(t.Context(), gitRepo, true, tt.BaseSha, tt.HeadSha)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, diffPaths)
|
||||
})
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
"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"
|
||||
@@ -158,7 +157,7 @@ diff --git "\\a/README.md" "\\b/README.md"
|
||||
}
|
||||
for _, testcase := range tests {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo)
|
||||
got, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), testcase.skipTo)
|
||||
if (err != nil) != testcase.wantErr {
|
||||
t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr)
|
||||
return
|
||||
@@ -377,7 +376,7 @@ index 6961180..9ba1a00 100644
|
||||
|
||||
for _, testcase := range tests {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
got, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
got, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
if (err != nil) != testcase.wantErr {
|
||||
t.Errorf("ParsePatch(%q) error = %v, wantErr %v", testcase.name, err, testcase.wantErr)
|
||||
return
|
||||
@@ -420,21 +419,21 @@ index 0000000..6bb8f39
|
||||
diffBuilder.WriteString("+line" + strconv.Itoa(i) + "\n")
|
||||
}
|
||||
diff = diffBuilder.String()
|
||||
result, err := ParsePatch(db.DefaultContext, 20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
result, err := ParsePatch(t.Context(), 20, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("There should not be an error: %v", err)
|
||||
}
|
||||
if !result.Files[0].IsIncomplete {
|
||||
t.Errorf("Files should be incomplete! %v", result.Files[0])
|
||||
}
|
||||
result, err = ParsePatch(db.DefaultContext, 40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
result, err = ParsePatch(t.Context(), 40, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("There should not be an error: %v", err)
|
||||
}
|
||||
if result.Files[0].IsIncomplete {
|
||||
t.Errorf("Files should not be incomplete! %v", result.Files[0])
|
||||
}
|
||||
result, err = ParsePatch(db.DefaultContext, 40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
result, err = ParsePatch(t.Context(), 40, 5, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("There should not be an error: %v", err)
|
||||
}
|
||||
@@ -465,14 +464,14 @@ index 0000000..6bb8f39
|
||||
diffBuilder.WriteString("+line" + strconv.Itoa(35) + "\n")
|
||||
diff = diffBuilder.String()
|
||||
|
||||
result, err = ParsePatch(db.DefaultContext, 20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
result, err = ParsePatch(t.Context(), 20, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("There should not be an error: %v", err)
|
||||
}
|
||||
if !result.Files[0].IsIncomplete {
|
||||
t.Errorf("Files should be incomplete! %v", result.Files[0])
|
||||
}
|
||||
result, err = ParsePatch(db.DefaultContext, 40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
result, err = ParsePatch(t.Context(), 40, 4096, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("There should not be an error: %v", err)
|
||||
}
|
||||
@@ -491,7 +490,7 @@ index 0000000..6bb8f39
|
||||
Docker Pulls
|
||||
+ cut off
|
||||
+ cut off`
|
||||
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
|
||||
if err != nil {
|
||||
t.Errorf("ParsePatch failed: %s", err)
|
||||
}
|
||||
@@ -507,7 +506,7 @@ index 0000000..6bb8f39
|
||||
Docker Pulls
|
||||
+ cut off
|
||||
+ cut off`
|
||||
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
|
||||
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
|
||||
if err != nil {
|
||||
t.Errorf("ParsePatch failed: %s", err)
|
||||
}
|
||||
@@ -523,7 +522,7 @@ index 0000000..6bb8f39
|
||||
Docker Pulls
|
||||
+ cut off
|
||||
+ cut off`
|
||||
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
|
||||
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
|
||||
if err != nil {
|
||||
t.Errorf("ParsePatch failed: %s", err)
|
||||
}
|
||||
@@ -539,7 +538,7 @@ index 0000000..6bb8f39
|
||||
Docker Pulls
|
||||
+ cut off
|
||||
+ cut off`
|
||||
_, err = ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
|
||||
_, err = ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
|
||||
if err != nil {
|
||||
t.Errorf("ParsePatch failed: %s", err)
|
||||
}
|
||||
@@ -571,7 +570,7 @@ func TestDiff_LoadCommentsNoOutdated(t *testing.T) {
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
diff := setupDefaultDiff()
|
||||
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, false))
|
||||
assert.NoError(t, diff.LoadComments(t.Context(), issue, user, false))
|
||||
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
|
||||
}
|
||||
|
||||
@@ -581,7 +580,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2})
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
diff := setupDefaultDiff()
|
||||
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user, true))
|
||||
assert.NoError(t, diff.LoadComments(t.Context(), issue, user, true))
|
||||
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 3)
|
||||
}
|
||||
|
||||
@@ -637,6 +636,6 @@ func TestNoCrashes(t *testing.T) {
|
||||
}
|
||||
for _, testcase := range tests {
|
||||
// It shouldn't crash, so don't care about the output.
|
||||
ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
@@ -204,7 +203,7 @@ index 0000000..68972a9
|
||||
|
||||
for _, testcase := range tests {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
diff, err := ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
diff, err := ParsePatch(t.Context(), setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
for i, expected := range testcase.infos {
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
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"
|
||||
@@ -18,30 +17,30 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// Fake issue with assignees
|
||||
issue, err := issues_model.GetIssueByID(db.DefaultContext, 1)
|
||||
issue, err := issues_model.GetIssueByID(t.Context(), 1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = issue.LoadAttributes(db.DefaultContext)
|
||||
err = issue.LoadAttributes(t.Context())
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, issue.Assignees, 1)
|
||||
|
||||
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
|
||||
user1, err := user_model.GetUserByID(t.Context(), 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check if he got removed
|
||||
isAssigned, err := issues_model.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
|
||||
isAssigned, err := issues_model.IsUserAssignedToIssue(t.Context(), issue, user1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, isAssigned)
|
||||
|
||||
// Clean everyone
|
||||
err = DeleteNotPassedAssignee(db.DefaultContext, issue, user1, []*user_model.User{})
|
||||
err = DeleteNotPassedAssignee(t.Context(), issue, user1, []*user_model.User{})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, issue.Assignees)
|
||||
|
||||
// Reload to check they're gone
|
||||
issue.ResetAttributesLoaded()
|
||||
assert.NoError(t, issue.LoadAssignees(db.DefaultContext))
|
||||
assert.NoError(t, issue.LoadAssignees(t.Context()))
|
||||
assert.Empty(t, issue.Assignees)
|
||||
assert.Empty(t, issue.Assignee)
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -61,7 +60,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -88,7 +87,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, "non-existing-branch"))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, "non-existing-branch"))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -114,7 +113,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -140,7 +139,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
|
||||
issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 4}
|
||||
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
}
|
||||
@@ -173,7 +172,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, "non-existing-branch"))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, "non-existing-branch"))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -208,7 +207,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -243,7 +242,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
|
||||
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertExistsAndLoadBean(t, commentBean)
|
||||
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
@@ -293,7 +292,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, commentBean2)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
|
||||
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
|
||||
unittest.AssertNotExistsBean(t, commentBean)
|
||||
unittest.AssertNotExistsBean(t, commentBean2)
|
||||
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -35,7 +34,7 @@ func TestGetRefEndNamesAndURLs(t *testing.T) {
|
||||
func TestIssue_DeleteIssue(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
|
||||
issueIDs, err := issues_model.GetIssueIDsByRepoID(t.Context(), 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, issueIDs, 5)
|
||||
|
||||
@@ -44,43 +43,43 @@ func TestIssue_DeleteIssue(t *testing.T) {
|
||||
ID: issueIDs[2],
|
||||
}
|
||||
|
||||
_, err = deleteIssue(db.DefaultContext, issue)
|
||||
_, err = deleteIssue(t.Context(), issue)
|
||||
assert.NoError(t, err)
|
||||
issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
|
||||
issueIDs, err = issues_model.GetIssueIDsByRepoID(t.Context(), 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, issueIDs, 4)
|
||||
|
||||
// check attachment removal
|
||||
attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4)
|
||||
attachments, err := repo_model.GetAttachmentsByIssueID(t.Context(), 4)
|
||||
assert.NoError(t, err)
|
||||
issue, err = issues_model.GetIssueByID(db.DefaultContext, 4)
|
||||
issue, err = issues_model.GetIssueByID(t.Context(), 4)
|
||||
assert.NoError(t, err)
|
||||
_, err = deleteIssue(db.DefaultContext, issue)
|
||||
_, err = deleteIssue(t.Context(), issue)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, attachments, 2)
|
||||
for i := range attachments {
|
||||
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachments[i].UUID)
|
||||
attachment, err := repo_model.GetAttachmentByUUID(t.Context(), attachments[i].UUID)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
|
||||
assert.Nil(t, attachment)
|
||||
}
|
||||
|
||||
// check issue dependencies
|
||||
user, err := user_model.GetUserByID(db.DefaultContext, 1)
|
||||
user, err := user_model.GetUserByID(t.Context(), 1)
|
||||
assert.NoError(t, err)
|
||||
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
|
||||
issue1, err := issues_model.GetIssueByID(t.Context(), 1)
|
||||
assert.NoError(t, err)
|
||||
issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2)
|
||||
issue2, err := issues_model.GetIssueByID(t.Context(), 2)
|
||||
assert.NoError(t, err)
|
||||
err = issues_model.CreateIssueDependency(db.DefaultContext, user, issue1, issue2)
|
||||
err = issues_model.CreateIssueDependency(t.Context(), user, issue1, issue2)
|
||||
assert.NoError(t, err)
|
||||
left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
||||
left, err := issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, left)
|
||||
|
||||
_, err = deleteIssue(db.DefaultContext, issue2)
|
||||
_, err = deleteIssue(t.Context(), issue2)
|
||||
assert.NoError(t, err)
|
||||
left, err = issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
|
||||
left, err = issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, left)
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
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"
|
||||
@@ -33,7 +32,7 @@ func TestIssue_AddLabels(t *testing.T) {
|
||||
labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID})
|
||||
}
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
|
||||
assert.NoError(t, AddLabels(db.DefaultContext, issue, doer, labels))
|
||||
assert.NoError(t, AddLabels(t.Context(), issue, doer, labels))
|
||||
for _, labelID := range test.labelIDs {
|
||||
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: labelID})
|
||||
}
|
||||
@@ -56,7 +55,7 @@ func TestIssue_AddLabel(t *testing.T) {
|
||||
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
|
||||
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: test.labelID})
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
|
||||
assert.NoError(t, AddLabel(db.DefaultContext, issue, doer, label))
|
||||
assert.NoError(t, AddLabel(t.Context(), issue, doer, label))
|
||||
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
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"
|
||||
@@ -23,8 +22,8 @@ func TestChangeMilestoneAssign(t *testing.T) {
|
||||
|
||||
oldMilestoneID := issue.MilestoneID
|
||||
issue.MilestoneID = 2
|
||||
assert.NoError(t, issue.LoadMilestone(db.DefaultContext))
|
||||
assert.NoError(t, ChangeMilestoneAssign(db.DefaultContext, issue, doer, oldMilestoneID))
|
||||
assert.NoError(t, issue.LoadMilestone(t.Context()))
|
||||
assert.NoError(t, ChangeMilestoneAssign(t.Context(), issue, doer, oldMilestoneID))
|
||||
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
||||
IssueID: issue.ID,
|
||||
Type: issues_model.CommentTypeMilestone,
|
||||
@@ -36,7 +35,7 @@ func TestChangeMilestoneAssign(t *testing.T) {
|
||||
|
||||
oldMilestoneID = issue.MilestoneID
|
||||
issue.MilestoneID = 0
|
||||
assert.NoError(t, ChangeMilestoneAssign(db.DefaultContext, issue, doer, oldMilestoneID))
|
||||
assert.NoError(t, ChangeMilestoneAssign(t.Context(), issue, doer, oldMilestoneID))
|
||||
assert.EqualValues(t, 0, issue.MilestoneID)
|
||||
assert.Nil(t, issue.Milestone)
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -20,9 +19,9 @@ func addReaction(t *testing.T, doer *user_model.User, issue *issues_model.Issue,
|
||||
var reaction *issues_model.Reaction
|
||||
var err error
|
||||
if comment == nil {
|
||||
reaction, err = CreateIssueReaction(db.DefaultContext, doer, issue, content)
|
||||
reaction, err = CreateIssueReaction(t.Context(), doer, issue, content)
|
||||
} else {
|
||||
reaction, err = CreateCommentReaction(db.DefaultContext, doer, comment, content)
|
||||
reaction, err = CreateCommentReaction(t.Context(), doer, comment, content)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, reaction)
|
||||
@@ -47,7 +46,7 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
|
||||
addReaction(t, user1, issue, nil, "heart")
|
||||
|
||||
reaction, err := CreateIssueReaction(db.DefaultContext, user1, issue, "heart")
|
||||
reaction, err := CreateIssueReaction(t.Context(), user1, issue, "heart")
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, issues_model.ErrReactionAlreadyExist{Reaction: "heart"}, err)
|
||||
|
||||
@@ -63,7 +62,7 @@ func TestIssueDeleteReaction(t *testing.T) {
|
||||
|
||||
addReaction(t, user1, issue, nil, "heart")
|
||||
|
||||
err := issues_model.DeleteIssueReaction(db.DefaultContext, user1.ID, issue.ID, "heart")
|
||||
err := issues_model.DeleteIssueReaction(t.Context(), user1.ID, issue.ID, "heart")
|
||||
assert.NoError(t, err)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue.ID})
|
||||
@@ -91,12 +90,12 @@ func TestIssueReactionCount(t *testing.T) {
|
||||
addReaction(t, user4, issue, nil, "heart")
|
||||
addReaction(t, ghost, issue, nil, "-1")
|
||||
|
||||
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
|
||||
reactionsList, _, err := issues_model.FindReactions(t.Context(), issues_model.FindReactionsOptions{
|
||||
IssueID: issue.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, reactionsList, 7)
|
||||
_, err = reactionsList.LoadUsers(db.DefaultContext, repo)
|
||||
_, err = reactionsList.LoadUsers(t.Context(), repo)
|
||||
assert.NoError(t, err)
|
||||
|
||||
reactions := reactionsList.GroupByType()
|
||||
@@ -137,7 +136,7 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
addReaction(t, org3, nil, comment, "heart")
|
||||
addReaction(t, user4, nil, comment, "+1")
|
||||
|
||||
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
|
||||
reactionsList, _, err := issues_model.FindReactions(t.Context(), issues_model.FindReactionsOptions{
|
||||
IssueID: comment.IssueID,
|
||||
CommentID: comment.ID,
|
||||
})
|
||||
@@ -156,7 +155,7 @@ func TestIssueCommentReactionCount(t *testing.T) {
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 1})
|
||||
|
||||
addReaction(t, user1, nil, comment, "heart")
|
||||
assert.NoError(t, issues_model.DeleteCommentReaction(db.DefaultContext, user1.ID, comment.IssueID, comment.ID, "heart"))
|
||||
assert.NoError(t, issues_model.DeleteCommentReaction(t.Context(), user1.ID, comment.IssueID, comment.ID, "heart"))
|
||||
|
||||
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: comment.IssueID, CommentID: comment.ID})
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package issue
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
@@ -44,7 +43,7 @@ func Test_Suggestion(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.keyword, func(t *testing.T) {
|
||||
issues, err := GetSuggestion(db.DefaultContext, repo1, testCase.isPull, testCase.keyword)
|
||||
issues, err := GetSuggestion(t.Context(), repo1, testCase.isPull, testCase.keyword)
|
||||
assert.NoError(t, err)
|
||||
|
||||
issueIndexes := make([]int64, 0, len(issues))
|
||||
|
@@ -18,7 +18,6 @@ import (
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -68,7 +67,7 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Re
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer})
|
||||
issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1, Repo: repo, Poster: doer})
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2, Issue: issue})
|
||||
require.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
require.NoError(t, issue.LoadRepo(t.Context()))
|
||||
return doer, repo, issue, comment
|
||||
}
|
||||
|
||||
@@ -252,7 +251,7 @@ func TestTemplateSelection(t *testing.T) {
|
||||
|
||||
func TestTemplateServices(t *testing.T) {
|
||||
doer, _, issue, comment := prepareMailerTest(t)
|
||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
assert.NoError(t, issue.LoadRepo(t.Context()))
|
||||
|
||||
expect := func(t *testing.T, issue *issues_model.Issue, comment *issues_model.Comment, doer *user_model.User,
|
||||
actionType activities_model.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
|
||||
@@ -447,7 +446,7 @@ func TestGenerateMessageIDForActionsWorkflowRunStatusEmail(t *testing.T) {
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: 795, RepoID: repo.ID})
|
||||
assert.NoError(t, run.LoadAttributes(db.DefaultContext))
|
||||
assert.NoError(t, run.LoadAttributes(t.Context()))
|
||||
msgID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run)
|
||||
assert.Equal(t, "<user2/repo2/actions/runs/191@localhost>", msgID)
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/models/user"
|
||||
gitea_context "code.gitea.io/gitea/services/context"
|
||||
@@ -45,7 +44,7 @@ func TestRenderHelperMention(t *testing.T) {
|
||||
assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(giteaCtx, userPublic))
|
||||
assert.False(t, FormalRenderHelperFuncs().IsUsernameMentionable(giteaCtx, userPrivate))
|
||||
|
||||
giteaCtx.Doer, err = user.GetUserByName(db.DefaultContext, userPrivate)
|
||||
giteaCtx.Doer, err = user.GetUserByName(t.Context(), userPrivate)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(giteaCtx, userPublic))
|
||||
assert.True(t, FormalRenderHelperFuncs().IsUsernameMentionable(giteaCtx, userPrivate))
|
||||
|
@@ -45,7 +45,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
||||
)
|
||||
|
||||
err := migrateRepository(db.DefaultContext, user, downloader, uploader, base.MigrateOptions{
|
||||
err := migrateRepository(t.Context(), user, downloader, uploader, base.MigrateOptions{
|
||||
CloneAddr: "https://github.com/go-xorm/builder",
|
||||
RepoName: repoName,
|
||||
AuthUsername: "",
|
||||
@@ -66,14 +66,14 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.True(t, repo.HasWiki())
|
||||
assert.Equal(t, repo_model.RepositoryReady, repo.Status)
|
||||
|
||||
milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
|
||||
milestones, err := db.Find[issues_model.Milestone](t.Context(), issues_model.FindMilestoneOptions{
|
||||
RepoID: repo.ID,
|
||||
IsClosed: optional.Some(false),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, milestones, 1)
|
||||
|
||||
milestones, err = db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
|
||||
milestones, err = db.Find[issues_model.Milestone](t.Context(), issues_model.FindMilestoneOptions{
|
||||
RepoID: repo.ID,
|
||||
IsClosed: optional.Some(true),
|
||||
})
|
||||
@@ -84,7 +84,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, labels, 12)
|
||||
|
||||
releases, err := db.Find[repo_model.Release](db.DefaultContext, repo_model.FindReleasesOptions{
|
||||
releases, err := db.Find[repo_model.Release](t.Context(), repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
@@ -95,7 +95,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, releases, 8)
|
||||
|
||||
releases, err = db.Find[repo_model.Release](db.DefaultContext, repo_model.FindReleasesOptions{
|
||||
releases, err = db.Find[repo_model.Release](t.Context(), repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
@@ -106,23 +106,23 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, releases, 1)
|
||||
|
||||
issues, err := issues_model.Issues(db.DefaultContext, &issues_model.IssuesOptions{
|
||||
issues, err := issues_model.Issues(t.Context(), &issues_model.IssuesOptions{
|
||||
RepoIDs: []int64{repo.ID},
|
||||
IsPull: optional.Some(false),
|
||||
SortType: "oldest",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, issues, 15)
|
||||
assert.NoError(t, issues[0].LoadDiscussComments(db.DefaultContext))
|
||||
assert.NoError(t, issues[0].LoadDiscussComments(t.Context()))
|
||||
assert.Empty(t, issues[0].Comments)
|
||||
|
||||
pulls, _, err := issues_model.PullRequests(db.DefaultContext, repo.ID, &issues_model.PullRequestsOptions{
|
||||
pulls, _, err := issues_model.PullRequests(t.Context(), repo.ID, &issues_model.PullRequestsOptions{
|
||||
SortType: "oldest",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pulls, 30)
|
||||
assert.NoError(t, pulls[0].LoadIssue(db.DefaultContext))
|
||||
assert.NoError(t, pulls[0].Issue.LoadDiscussComments(db.DefaultContext))
|
||||
assert.NoError(t, pulls[0].LoadIssue(t.Context()))
|
||||
assert.NoError(t, pulls[0].Issue.LoadDiscussComments(t.Context()))
|
||||
assert.Len(t, pulls[0].Issue.Comments, 2)
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ func TestGiteaUploadRemapExternalUser(t *testing.T) {
|
||||
LoginSourceID: 0,
|
||||
Provider: structs.GiteaService.Name(),
|
||||
}
|
||||
err = user_model.LinkExternalToUser(db.DefaultContext, linkedUser, externalLoginUser)
|
||||
err = user_model.LinkExternalToUser(t.Context(), linkedUser, externalLoginUser)
|
||||
assert.NoError(t, err)
|
||||
|
||||
//
|
||||
|
@@ -6,7 +6,6 @@ package org
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -22,17 +21,17 @@ func TestMain(m *testing.M) {
|
||||
func TestDeleteOrganization(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 6})
|
||||
assert.NoError(t, DeleteOrganization(db.DefaultContext, org, false))
|
||||
assert.NoError(t, DeleteOrganization(t.Context(), org, false))
|
||||
unittest.AssertNotExistsBean(t, &organization.Organization{ID: 6})
|
||||
unittest.AssertNotExistsBean(t, &organization.OrgUser{OrgID: 6})
|
||||
unittest.AssertNotExistsBean(t, &organization.Team{OrgID: 6})
|
||||
|
||||
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
err := DeleteOrganization(db.DefaultContext, org, false)
|
||||
err := DeleteOrganization(t.Context(), org, false)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, repo_model.IsErrUserOwnRepos(err))
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 5})
|
||||
assert.Error(t, DeleteOrganization(db.DefaultContext, user, false))
|
||||
assert.Error(t, DeleteOrganization(t.Context(), user, false))
|
||||
unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{})
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ import (
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@@ -259,10 +260,9 @@ func AddTeamMember(ctx context.Context, team *organization.Team, user *user_mode
|
||||
log.Error("GetTeamRepositories failed: %v", err)
|
||||
}
|
||||
|
||||
// FIXME: in the goroutine, it can't access the "ctx", it could only use db.DefaultContext at the moment
|
||||
go func(repos []*repo_model.Repository) {
|
||||
for _, repo := range repos {
|
||||
if err = repo_model.WatchRepo(db.DefaultContext, user, repo, true); err != nil {
|
||||
if err = repo_model.WatchRepo(graceful.GetManager().ShutdownContext(), user, repo, true); err != nil {
|
||||
log.Error("watch repo failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
@@ -25,7 +24,7 @@ func TestTeam_AddMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
test := func(team *organization.Team, user *user_model.User) {
|
||||
assert.NoError(t, AddTeamMember(db.DefaultContext, team, user))
|
||||
assert.NoError(t, AddTeamMember(t.Context(), team, user))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: user.ID, TeamID: team.ID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@@ -44,7 +43,7 @@ func TestTeam_RemoveMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
testSuccess := func(team *organization.Team, user *user_model.User) {
|
||||
assert.NoError(t, RemoveTeamMember(db.DefaultContext, team, user))
|
||||
assert.NoError(t, RemoveTeamMember(t.Context(), team, user))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: user.ID, TeamID: team.ID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
|
||||
}
|
||||
@@ -59,7 +58,7 @@ func TestTeam_RemoveMember(t *testing.T) {
|
||||
testSuccess(team2, user2)
|
||||
testSuccess(team3, user2)
|
||||
|
||||
err := RemoveTeamMember(db.DefaultContext, team1, user2)
|
||||
err := RemoveTeamMember(t.Context(), team1, user2)
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
}
|
||||
|
||||
@@ -68,7 +67,7 @@ func TestNewTeam(t *testing.T) {
|
||||
|
||||
const teamName = "newTeamName"
|
||||
team := &organization.Team{Name: teamName, OrgID: 3}
|
||||
assert.NoError(t, NewTeam(db.DefaultContext, team))
|
||||
assert.NoError(t, NewTeam(t.Context(), team))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: teamName})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@@ -82,7 +81,7 @@ func TestUpdateTeam(t *testing.T) {
|
||||
team.Name = "newName"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
team.AccessMode = perm.AccessModeAdmin
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, true, false))
|
||||
assert.NoError(t, UpdateTeam(t.Context(), team, true, false))
|
||||
|
||||
team = unittest.AssertExistsAndLoadBean(t, &organization.Team{Name: "newName"})
|
||||
assert.True(t, strings.HasPrefix(team.Description, "A long description!"))
|
||||
@@ -101,7 +100,7 @@ func TestUpdateTeam2(t *testing.T) {
|
||||
team.LowerName = "owners"
|
||||
team.Name = "Owners"
|
||||
team.Description = strings.Repeat("A long description!", 100)
|
||||
err := UpdateTeam(db.DefaultContext, team, true, false)
|
||||
err := UpdateTeam(t.Context(), team, true, false)
|
||||
assert.True(t, organization.IsErrTeamAlreadyExist(err))
|
||||
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
|
||||
@@ -111,7 +110,7 @@ func TestDeleteTeam(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 2})
|
||||
assert.NoError(t, DeleteTeam(db.DefaultContext, team))
|
||||
assert.NoError(t, DeleteTeam(t.Context(), team))
|
||||
unittest.AssertNotExistsBean(t, &organization.Team{ID: team.ID})
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: team.ID})
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{TeamID: team.ID})
|
||||
@@ -119,7 +118,7 @@ func TestDeleteTeam(t *testing.T) {
|
||||
// check that team members don't have "leftover" access to repos
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||
accessMode, err := access_model.AccessLevel(db.DefaultContext, user, repo)
|
||||
accessMode, err := access_model.AccessLevel(t.Context(), user, repo)
|
||||
assert.NoError(t, err)
|
||||
assert.Less(t, accessMode, perm.AccessModeWrite)
|
||||
}
|
||||
@@ -128,7 +127,7 @@ func TestAddTeamMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
test := func(team *organization.Team, user *user_model.User) {
|
||||
assert.NoError(t, AddTeamMember(db.DefaultContext, team, user))
|
||||
assert.NoError(t, AddTeamMember(t.Context(), team, user))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: user.ID, TeamID: team.ID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID}, &user_model.User{ID: team.OrgID})
|
||||
}
|
||||
@@ -147,7 +146,7 @@ func TestRemoveTeamMember(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
testSuccess := func(team *organization.Team, user *user_model.User) {
|
||||
assert.NoError(t, RemoveTeamMember(db.DefaultContext, team, user))
|
||||
assert.NoError(t, RemoveTeamMember(t.Context(), team, user))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamUser{UID: user.ID, TeamID: team.ID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: team.ID})
|
||||
}
|
||||
@@ -162,7 +161,7 @@ func TestRemoveTeamMember(t *testing.T) {
|
||||
testSuccess(team2, user2)
|
||||
testSuccess(team3, user2)
|
||||
|
||||
err := RemoveTeamMember(db.DefaultContext, team1, user2)
|
||||
err := RemoveTeamMember(t.Context(), team1, user2)
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
}
|
||||
|
||||
@@ -171,7 +170,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
|
||||
testTeamRepositories := func(teamID int64, repoIDs []int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
repos, err := repo_model.GetTeamRepositories(db.DefaultContext, &repo_model.SearchTeamRepoOptions{
|
||||
repos, err := repo_model.GetTeamRepositories(t.Context(), &repo_model.SearchTeamRepoOptions{
|
||||
TeamID: team.ID,
|
||||
})
|
||||
assert.NoError(t, err, "%s: GetTeamRepositories", team.Name)
|
||||
@@ -179,13 +178,13 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
assert.Len(t, repos, len(repoIDs), "%s: repo count", team.Name)
|
||||
for i, rid := range repoIDs {
|
||||
if rid > 0 {
|
||||
assert.True(t, repo_service.HasRepository(db.DefaultContext, team, rid), "%s: HasRepository(%d) %d", rid, i)
|
||||
assert.True(t, repo_service.HasRepository(t.Context(), team, rid), "%s: HasRepository(%d) %d", rid, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get an admin user.
|
||||
user, err := user_model.GetUserByID(db.DefaultContext, 1)
|
||||
user, err := user_model.GetUserByID(t.Context(), 1)
|
||||
assert.NoError(t, err, "GetUserByID")
|
||||
|
||||
// Create org.
|
||||
@@ -195,17 +194,17 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
Type: user_model.UserTypeOrganization,
|
||||
Visibility: structs.VisibleTypePublic,
|
||||
}
|
||||
assert.NoError(t, organization.CreateOrganization(db.DefaultContext, org, user), "CreateOrganization")
|
||||
assert.NoError(t, organization.CreateOrganization(t.Context(), org, user), "CreateOrganization")
|
||||
|
||||
// Check Owner team.
|
||||
ownerTeam, err := org.GetOwnerTeam(db.DefaultContext)
|
||||
ownerTeam, err := org.GetOwnerTeam(t.Context())
|
||||
assert.NoError(t, err, "GetOwnerTeam")
|
||||
assert.True(t, ownerTeam.IncludesAllRepositories, "Owner team includes all repositories")
|
||||
|
||||
// Create repos.
|
||||
repoIDs := make([]int64, 0)
|
||||
for i := range 3 {
|
||||
r, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user, org.AsUser(),
|
||||
r, err := repo_service.CreateRepositoryDirectly(t.Context(), user, org.AsUser(),
|
||||
repo_service.CreateRepoOptions{Name: fmt.Sprintf("repo-%d", i)}, true)
|
||||
assert.NoError(t, err, "CreateRepository %d", i)
|
||||
if r != nil {
|
||||
@@ -213,7 +212,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
// Get fresh copy of Owner team after creating repos.
|
||||
ownerTeam, err = org.GetOwnerTeam(db.DefaultContext)
|
||||
ownerTeam, err = org.GetOwnerTeam(t.Context())
|
||||
assert.NoError(t, err, "GetOwnerTeam")
|
||||
|
||||
// Create teams and check repositories.
|
||||
@@ -253,7 +252,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
}
|
||||
for i, team := range teams {
|
||||
if i > 0 { // first team is Owner.
|
||||
assert.NoError(t, NewTeam(db.DefaultContext, team), "%s: NewTeam", team.Name)
|
||||
assert.NoError(t, NewTeam(t.Context(), team), "%s: NewTeam", team.Name)
|
||||
}
|
||||
testTeamRepositories(team.ID, teamRepos[i])
|
||||
}
|
||||
@@ -263,12 +262,12 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
teams[4].IncludesAllRepositories = true
|
||||
teamRepos[4] = repoIDs
|
||||
for i, team := range teams {
|
||||
assert.NoError(t, UpdateTeam(db.DefaultContext, team, false, true), "%s: UpdateTeam", team.Name)
|
||||
assert.NoError(t, UpdateTeam(t.Context(), team, false, true), "%s: UpdateTeam", team.Name)
|
||||
testTeamRepositories(team.ID, teamRepos[i])
|
||||
}
|
||||
|
||||
// Create repo and check teams repositories.
|
||||
r, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user, org.AsUser(), repo_service.CreateRepoOptions{Name: "repo-last"}, true)
|
||||
r, err := repo_service.CreateRepositoryDirectly(t.Context(), user, org.AsUser(), repo_service.CreateRepoOptions{Name: "repo-last"}, true)
|
||||
assert.NoError(t, err, "CreateRepository last")
|
||||
if r != nil {
|
||||
repoIDs = append(repoIDs, r.ID)
|
||||
@@ -281,7 +280,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
}
|
||||
|
||||
// Remove repo and check teams repositories.
|
||||
assert.NoError(t, repo_service.DeleteRepositoryDirectly(db.DefaultContext, repoIDs[0]), "DeleteRepository")
|
||||
assert.NoError(t, repo_service.DeleteRepositoryDirectly(t.Context(), repoIDs[0]), "DeleteRepository")
|
||||
teamRepos[0] = repoIDs[1:]
|
||||
teamRepos[1] = repoIDs[1:]
|
||||
teamRepos[3] = repoIDs[1:3]
|
||||
@@ -293,8 +292,8 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
// Wipe created items.
|
||||
for i, rid := range repoIDs {
|
||||
if i > 0 { // first repo already deleted.
|
||||
assert.NoError(t, repo_service.DeleteRepositoryDirectly(db.DefaultContext, rid), "DeleteRepository %d", i)
|
||||
assert.NoError(t, repo_service.DeleteRepositoryDirectly(t.Context(), rid), "DeleteRepository %d", i)
|
||||
}
|
||||
}
|
||||
assert.NoError(t, DeleteOrganization(db.DefaultContext, org, false), "DeleteOrganization")
|
||||
assert.NoError(t, DeleteOrganization(t.Context(), org, false), "DeleteOrganization")
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package org
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -24,7 +23,7 @@ func TestUser_RemoveMember(t *testing.T) {
|
||||
// remove a user that is a member
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{UID: user4.ID, OrgID: org.ID})
|
||||
prevNumMembers := org.NumMembers
|
||||
assert.NoError(t, RemoveOrgUser(db.DefaultContext, org, user4))
|
||||
assert.NoError(t, RemoveOrgUser(t.Context(), org, user4))
|
||||
unittest.AssertNotExistsBean(t, &organization.OrgUser{UID: user4.ID, OrgID: org.ID})
|
||||
|
||||
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: org.ID})
|
||||
@@ -33,7 +32,7 @@ func TestUser_RemoveMember(t *testing.T) {
|
||||
// remove a user that is not a member
|
||||
unittest.AssertNotExistsBean(t, &organization.OrgUser{UID: user5.ID, OrgID: org.ID})
|
||||
prevNumMembers = org.NumMembers
|
||||
assert.NoError(t, RemoveOrgUser(db.DefaultContext, org, user5))
|
||||
assert.NoError(t, RemoveOrgUser(t.Context(), org, user5))
|
||||
unittest.AssertNotExistsBean(t, &organization.OrgUser{UID: user5.ID, OrgID: org.ID})
|
||||
|
||||
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: org.ID})
|
||||
@@ -50,7 +49,7 @@ func TestRemoveOrgUser(t *testing.T) {
|
||||
if unittest.GetBean(t, &organization.OrgUser{OrgID: org.ID, UID: user.ID}) != nil {
|
||||
expectedNumMembers--
|
||||
}
|
||||
assert.NoError(t, RemoveOrgUser(db.DefaultContext, org, user))
|
||||
assert.NoError(t, RemoveOrgUser(t.Context(), org, user))
|
||||
unittest.AssertNotExistsBean(t, &organization.OrgUser{OrgID: org.ID, UID: user.ID})
|
||||
org = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: org.ID})
|
||||
assert.Equal(t, expectedNumMembers, org.NumMembers)
|
||||
@@ -66,7 +65,7 @@ func TestRemoveOrgUser(t *testing.T) {
|
||||
org3 = unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
|
||||
testSuccess(org3, user4)
|
||||
|
||||
err := RemoveOrgUser(db.DefaultContext, org7, user5)
|
||||
err := RemoveOrgUser(t.Context(), org7, user5)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{OrgID: org7.ID, UID: user5.ID})
|
||||
|
@@ -4,16 +4,13 @@
|
||||
package arch
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// https://gitlab.archlinux.org/pacman/pacman/-/blob/d55b47e5512808b67bc944feb20c2bcc6c1a4c45/lib/libalpm/version.c
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func parseEVR(evr string) (epoch, version, release string) {
|
||||
if before, after, f := strings.Cut(evr, ":"); f {
|
||||
epoch = before
|
||||
|
@@ -15,7 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/packages"
|
||||
container_module "code.gitea.io/gitea/modules/packages/container"
|
||||
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
// UpdateRepositoryNames updates the repository name property for all packages of the specific owner
|
||||
|
@@ -31,10 +31,10 @@ func Test_Projects(t *testing.T) {
|
||||
IssueID: 1,
|
||||
ProjectColumnID: 4,
|
||||
}
|
||||
err := db.Insert(db.DefaultContext, &pi1)
|
||||
err := db.Insert(t.Context(), &pi1)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
_, err = db.DeleteByID[project_model.ProjectIssue](db.DefaultContext, pi1.ID)
|
||||
_, err = db.DeleteByID[project_model.ProjectIssue](t.Context(), pi1.ID)
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
@@ -43,14 +43,14 @@ func Test_Projects(t *testing.T) {
|
||||
IssueID: 4,
|
||||
ProjectColumnID: 4,
|
||||
}
|
||||
err = db.Insert(db.DefaultContext, &pi2)
|
||||
err = db.Insert(t.Context(), &pi2)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
_, err = db.DeleteByID[project_model.ProjectIssue](db.DefaultContext, pi2.ID)
|
||||
_, err = db.DeleteByID[project_model.ProjectIssue](t.Context(), pi2.ID)
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
projects, err := db.Find[project_model.Project](db.DefaultContext, project_model.SearchOptions{
|
||||
projects, err := db.Find[project_model.Project](t.Context(), project_model.SearchOptions{
|
||||
OwnerID: user2.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -58,7 +58,7 @@ func Test_Projects(t *testing.T) {
|
||||
assert.EqualValues(t, 4, projects[0].ID)
|
||||
|
||||
t.Run("Authenticated user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
Owner: user2,
|
||||
Doer: user2,
|
||||
})
|
||||
@@ -68,7 +68,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Anonymous user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
AllPublic: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -77,7 +77,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Authenticated user with no permission to the private repo", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
Owner: user2,
|
||||
Doer: user4,
|
||||
})
|
||||
@@ -94,10 +94,10 @@ func Test_Projects(t *testing.T) {
|
||||
Type: project_model.TypeOrganization,
|
||||
TemplateType: project_model.TemplateTypeBasicKanban,
|
||||
}
|
||||
err := project_model.NewProject(db.DefaultContext, &project1)
|
||||
err := project_model.NewProject(t.Context(), &project1)
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
err := project_model.DeleteProjectByID(db.DefaultContext, project1.ID)
|
||||
err := project_model.DeleteProjectByID(t.Context(), project1.ID)
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
@@ -105,27 +105,27 @@ func Test_Projects(t *testing.T) {
|
||||
Title: "column 1",
|
||||
ProjectID: project1.ID,
|
||||
}
|
||||
err = project_model.NewColumn(db.DefaultContext, &column1)
|
||||
err = project_model.NewColumn(t.Context(), &column1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
column2 := project_model.Column{
|
||||
Title: "column 2",
|
||||
ProjectID: project1.ID,
|
||||
}
|
||||
err = project_model.NewColumn(db.DefaultContext, &column2)
|
||||
err = project_model.NewColumn(t.Context(), &column2)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// issue 6 belongs to private repo 3 under org 3
|
||||
issue6 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 6})
|
||||
err = issues_model.IssueAssignOrRemoveProject(db.DefaultContext, issue6, user2, project1.ID, column1.ID)
|
||||
err = issues_model.IssueAssignOrRemoveProject(t.Context(), issue6, user2, project1.ID, column1.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// issue 16 belongs to public repo 16 under org 3
|
||||
issue16 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 16})
|
||||
err = issues_model.IssueAssignOrRemoveProject(db.DefaultContext, issue16, user2, project1.ID, column1.ID)
|
||||
err = issues_model.IssueAssignOrRemoveProject(t.Context(), issue16, user2, project1.ID, column1.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
projects, err := db.Find[project_model.Project](db.DefaultContext, project_model.SearchOptions{
|
||||
projects, err := db.Find[project_model.Project](t.Context(), project_model.SearchOptions{
|
||||
OwnerID: org3.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -133,7 +133,7 @@ func Test_Projects(t *testing.T) {
|
||||
assert.Equal(t, project1.ID, projects[0].ID)
|
||||
|
||||
t.Run("Authenticated user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
Owner: org3.AsUser(),
|
||||
Doer: userAdmin,
|
||||
})
|
||||
@@ -143,7 +143,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Anonymous user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
AllPublic: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -152,7 +152,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Authenticated user with no permission to the private repo", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
Owner: org3.AsUser(),
|
||||
Doer: user2,
|
||||
})
|
||||
@@ -165,7 +165,7 @@ func Test_Projects(t *testing.T) {
|
||||
t.Run("Repository projects", func(t *testing.T) {
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
projects, err := db.Find[project_model.Project](db.DefaultContext, project_model.SearchOptions{
|
||||
projects, err := db.Find[project_model.Project](t.Context(), project_model.SearchOptions{
|
||||
RepoID: repo1.ID,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -173,7 +173,7 @@ func Test_Projects(t *testing.T) {
|
||||
assert.EqualValues(t, 1, projects[0].ID)
|
||||
|
||||
t.Run("Authenticated user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
RepoIDs: []int64{repo1.ID},
|
||||
Doer: userAdmin,
|
||||
})
|
||||
@@ -185,7 +185,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Anonymous user", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
AllPublic: true,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -196,7 +196,7 @@ func Test_Projects(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Authenticated user with no permission to the private repo", func(t *testing.T) {
|
||||
columnIssues, err := LoadIssuesFromProject(db.DefaultContext, projects[0], &issues_model.IssuesOptions{
|
||||
columnIssues, err := LoadIssuesFromProject(t.Context(), projects[0], &issues_model.IssuesOptions{
|
||||
RepoIDs: []int64{repo1.ID},
|
||||
Doer: user2,
|
||||
})
|
||||
|
@@ -42,7 +42,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
StartPullRequestCheckImmediately(db.DefaultContext, pr)
|
||||
StartPullRequestCheckImmediately(t.Context(), pr)
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
|
@@ -11,7 +11,6 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
"code.gitea.io/gitea/modules/git/pipeline"
|
||||
@@ -40,7 +39,7 @@ func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string
|
||||
// 6. Take the output of cat-file --batch and check if each file in turn
|
||||
// to see if they're pointers to files in the LFS store associated with
|
||||
// the head repo and add them to the base repo if so
|
||||
go createLFSMetaObjectsFromCatFileBatch(db.DefaultContext, catFileBatchReader, &wg, pr)
|
||||
go createLFSMetaObjectsFromCatFileBatch(ctx, catFileBatchReader, &wg, pr)
|
||||
|
||||
// 5. Take the shas of the blobs and batch read them
|
||||
go pipeline.CatFileBatch(ctx, shasToBatchReader, catFileBatchWriter, &wg, tmpBasePath)
|
||||
|
@@ -7,7 +7,6 @@ package pull
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
@@ -40,18 +39,18 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), pr.BaseRepo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, _, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
mergeMessage, _, err := GetDefaultMergeMessage(t.Context(), gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from branch2 into master", mergeMessage)
|
||||
|
||||
pr.BaseRepoID = 1
|
||||
pr.HeadRepoID = 2
|
||||
mergeMessage, _, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
mergeMessage, _, err = GetDefaultMergeMessage(t.Context(), gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo1:branch2 into master", mergeMessage)
|
||||
}
|
||||
@@ -70,12 +69,12 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
||||
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
assert.NoError(t, pr.LoadBaseRepo(t.Context()))
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), pr.BaseRepo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, _, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
mergeMessage, _, err := GetDefaultMergeMessage(t.Context(), gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (!3) from branch2 into master", mergeMessage)
|
||||
@@ -84,7 +83,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
||||
pr.HeadRepoID = 2
|
||||
pr.BaseRepo = nil
|
||||
pr.HeadRepo = nil
|
||||
mergeMessage, _, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
mergeMessage, _, err = GetDefaultMergeMessage(t.Context(), gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo2:branch2 into master", mergeMessage)
|
||||
|
@@ -6,7 +6,6 @@ package pull_test
|
||||
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"
|
||||
@@ -19,11 +18,11 @@ func TestDismissReview(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{})
|
||||
assert.NoError(t, pull.LoadIssue(db.DefaultContext))
|
||||
assert.NoError(t, pull.LoadIssue(t.Context()))
|
||||
issue := pull.Issue
|
||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
||||
assert.NoError(t, issue.LoadRepo(t.Context()))
|
||||
reviewer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
review, err := issues_model.CreateReview(db.DefaultContext, issues_model.CreateReviewOptions{
|
||||
review, err := issues_model.CreateReview(t.Context(), issues_model.CreateReviewOptions{
|
||||
Issue: issue,
|
||||
Reviewer: reviewer,
|
||||
Type: issues_model.ReviewTypeReject,
|
||||
@@ -32,17 +31,17 @@ func TestDismissReview(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
issue.IsClosed = true
|
||||
pull.HasMerged = false
|
||||
assert.NoError(t, issues_model.UpdateIssueCols(db.DefaultContext, issue, "is_closed"))
|
||||
assert.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
||||
_, err = pull_service.DismissReview(db.DefaultContext, review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
||||
assert.NoError(t, issues_model.UpdateIssueCols(t.Context(), issue, "is_closed"))
|
||||
assert.NoError(t, pull.UpdateCols(t.Context(), "has_merged"))
|
||||
_, err = pull_service.DismissReview(t.Context(), review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, pull_service.IsErrDismissRequestOnClosedPR(err))
|
||||
|
||||
pull.HasMerged = true
|
||||
pull.Issue.IsClosed = false
|
||||
assert.NoError(t, issues_model.UpdateIssueCols(db.DefaultContext, issue, "is_closed"))
|
||||
assert.NoError(t, pull.UpdateCols(db.DefaultContext, "has_merged"))
|
||||
_, err = pull_service.DismissReview(db.DefaultContext, review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
||||
assert.NoError(t, issues_model.UpdateIssueCols(t.Context(), issue, "is_closed"))
|
||||
assert.NoError(t, pull.UpdateCols(t.Context(), "has_merged"))
|
||||
_, err = pull_service.DismissReview(t.Context(), review.ID, issue.RepoID, "", &user_model.User{}, false, false)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, pull_service.IsErrDismissRequestOnClosedPR(err))
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package pull_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
@@ -20,7 +19,7 @@ func TestRepoGetReviewers(t *testing.T) {
|
||||
// test public repo
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
ctx := db.DefaultContext
|
||||
ctx := t.Context()
|
||||
reviewers, err := pull_service.GetReviewers(ctx, repo1, 2, 0)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, reviewers, 1) {
|
||||
@@ -61,12 +60,12 @@ func TestRepoGetReviewerTeams(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
teams, err := pull_service.GetReviewerTeams(db.DefaultContext, repo2)
|
||||
teams, err := pull_service.GetReviewerTeams(t.Context(), repo2)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, teams)
|
||||
|
||||
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||
teams, err = pull_service.GetReviewerTeams(db.DefaultContext, repo3)
|
||||
teams, err = pull_service.GetReviewerTeams(t.Context(), repo3)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, teams, 2)
|
||||
}
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
@@ -106,7 +105,7 @@ func TestRelease_Create(t *testing.T) {
|
||||
|
||||
testPlayload := "testtest"
|
||||
|
||||
attach, err := attachment.NewAttachment(db.DefaultContext, &repo_model.Attachment{
|
||||
attach, err := attachment.NewAttachment(t.Context(), &repo_model.Attachment{
|
||||
RepoID: repo.ID,
|
||||
UploaderID: user.ID,
|
||||
Name: "test.txt",
|
||||
@@ -153,13 +152,13 @@ func TestRelease_Update(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
release, err := repo_model.GetRelease(db.DefaultContext, repo.ID, "v1.1.1")
|
||||
release, err := repo_model.GetRelease(t.Context(), repo.ID, "v1.1.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix := release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Note = "Changed note"
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(t.Context(), release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -177,13 +176,13 @@ func TestRelease_Update(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
release, err = repo_model.GetRelease(db.DefaultContext, repo.ID, "v1.2.1")
|
||||
release, err = repo_model.GetRelease(t.Context(), repo.ID, "v1.2.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(t.Context(), release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -201,14 +200,14 @@ func TestRelease_Update(t *testing.T) {
|
||||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}, nil, ""))
|
||||
release, err = repo_model.GetRelease(db.DefaultContext, repo.ID, "v1.3.1")
|
||||
release, err = repo_model.GetRelease(t.Context(), repo.ID, "v1.3.1")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
release.Note = "Changed note"
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(t.Context(), release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -232,42 +231,42 @@ func TestRelease_Update(t *testing.T) {
|
||||
release.IsDraft = false
|
||||
tagName := release.TagName
|
||||
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(db.DefaultContext, release.ID)
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, nil, nil))
|
||||
release, err = repo_model.GetReleaseByID(t.Context(), release.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tagName, release.TagName)
|
||||
|
||||
// Add new attachments
|
||||
samplePayload := "testtest"
|
||||
attach, err := attachment.NewAttachment(db.DefaultContext, &repo_model.Attachment{
|
||||
attach, err := attachment.NewAttachment(t.Context(), &repo_model.Attachment{
|
||||
RepoID: repo.ID,
|
||||
UploaderID: user.ID,
|
||||
Name: "test.txt",
|
||||
}, strings.NewReader(samplePayload), int64(len([]byte(samplePayload))))
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, []string{attach.UUID}, nil, nil))
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, []string{attach.UUID}, nil, nil))
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(t.Context(), release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
assert.Equal(t, attach.UUID, release.Attachments[0].UUID)
|
||||
assert.Equal(t, release.ID, release.Attachments[0].ReleaseID)
|
||||
assert.Equal(t, attach.Name, release.Attachments[0].Name)
|
||||
|
||||
// update the attachment name
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, nil, map[string]string{
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, nil, map[string]string{
|
||||
attach.UUID: "test2.txt",
|
||||
}))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(t.Context(), release))
|
||||
assert.Len(t, release.Attachments, 1)
|
||||
assert.Equal(t, attach.UUID, release.Attachments[0].UUID)
|
||||
assert.Equal(t, release.ID, release.Attachments[0].ReleaseID)
|
||||
assert.Equal(t, "test2.txt", release.Attachments[0].Name)
|
||||
|
||||
// delete the attachment
|
||||
assert.NoError(t, UpdateRelease(db.DefaultContext, user, gitRepo, release, nil, []string{attach.UUID}, nil))
|
||||
assert.NoError(t, UpdateRelease(t.Context(), user, gitRepo, release, nil, []string{attach.UUID}, nil))
|
||||
release.Attachments = nil
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(db.DefaultContext, release))
|
||||
assert.NoError(t, repo_model.GetReleaseAttachments(t.Context(), release))
|
||||
assert.Empty(t, release.Attachments)
|
||||
}
|
||||
|
||||
@@ -295,13 +294,13 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, release.CreatedUnix)
|
||||
releaseCreatedUnix := release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Note = "Changed note"
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -319,12 +318,12 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -342,13 +341,13 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
release.Note = "Changed note"
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
_, err = createTag(t.Context(), gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
@@ -28,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
func deleteFailedAdoptRepository(repoID int64) error {
|
||||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
|
||||
return db.WithTx(graceful.GetManager().ShutdownContext(), func(ctx context.Context) error {
|
||||
if err := deleteDBRepository(ctx, repoID); err != nil {
|
||||
return fmt.Errorf("deleteDBRepository: %w", err)
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
|
||||
// Non existent user
|
||||
//
|
||||
unadopted := &unadoptedRepositories{start: 0, end: 100}
|
||||
err := checkUnadoptedRepositories(db.DefaultContext, "notauser", []string{"repo"}, unadopted)
|
||||
err := checkUnadoptedRepositories(t.Context(), "notauser", []string{"repo"}, unadopted)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, unadopted.repositories)
|
||||
//
|
||||
@@ -54,14 +54,14 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
|
||||
repoName := "repo2"
|
||||
unadoptedRepoName := "unadopted"
|
||||
unadopted = &unadoptedRepositories{start: 0, end: 100}
|
||||
err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName, unadoptedRepoName}, unadopted)
|
||||
err = checkUnadoptedRepositories(t.Context(), userName, []string{repoName, unadoptedRepoName}, unadopted)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []string{path.Join(userName, unadoptedRepoName)}, unadopted.repositories)
|
||||
//
|
||||
// Existing (adopted) repository is not returned
|
||||
//
|
||||
unadopted = &unadoptedRepositories{start: 0, end: 100}
|
||||
err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName}, unadopted)
|
||||
err = checkUnadoptedRepositories(t.Context(), userName, []string{repoName}, unadopted)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, unadopted.repositories)
|
||||
assert.Equal(t, 0, unadopted.index)
|
||||
@@ -76,13 +76,13 @@ func TestListUnadoptedRepositories_ListOptions(t *testing.T) {
|
||||
}
|
||||
|
||||
opts := db.ListOptions{Page: 1, PageSize: 1}
|
||||
repoNames, count, err := ListUnadoptedRepositories(db.DefaultContext, "", &opts)
|
||||
repoNames, count, err := ListUnadoptedRepositories(t.Context(), "", &opts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
assert.Equal(t, unadoptedList[0], repoNames[0])
|
||||
|
||||
opts = db.ListOptions{Page: 2, PageSize: 1}
|
||||
repoNames, count, err = ListUnadoptedRepositories(db.DefaultContext, "", &opts)
|
||||
repoNames, count, err = ListUnadoptedRepositories(t.Context(), "", &opts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 2, count)
|
||||
assert.Equal(t, unadoptedList[1], repoNames[0])
|
||||
@@ -97,7 +97,7 @@ func TestAdoptRepository(t *testing.T) {
|
||||
destDir := filepath.Join(setting.RepoRootPath, user2.Name, "test-adopt.git")
|
||||
assert.NoError(t, unittest.SyncDirs(filepath.Join(setting.RepoRootPath, user2.Name, "repo1.git"), destDir))
|
||||
|
||||
adoptedRepo, err := AdoptRepository(db.DefaultContext, user2, user2, CreateRepoOptions{Name: "test-adopt"})
|
||||
adoptedRepo, err := AdoptRepository(t.Context(), user2, user2, CreateRepoOptions{Name: "test-adopt"})
|
||||
assert.NoError(t, err)
|
||||
repoTestAdopt := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "test-adopt"})
|
||||
assert.Equal(t, "sha1", repoTestAdopt.ObjectFormatName)
|
||||
@@ -113,7 +113,7 @@ func TestAdoptRepository(t *testing.T) {
|
||||
_ = os.RemoveAll(filepath.Join(destDir, "hooks", "update.d"))
|
||||
assert.NoError(t, os.WriteFile(filepath.Join(destDir, "hooks", "update.d"), []byte("tests"), os.ModePerm))
|
||||
|
||||
adoptedRepo, err = AdoptRepository(db.DefaultContext, user2, user2, CreateRepoOptions{Name: "test-adopt"})
|
||||
adoptedRepo, err = AdoptRepository(t.Context(), user2, user2, CreateRepoOptions{Name: "test-adopt"})
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, adoptedRepo)
|
||||
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/services/contexttest"
|
||||
|
||||
@@ -79,13 +78,13 @@ func TestArchive_Basic(t *testing.T) {
|
||||
inFlight[1] = tgzReq
|
||||
inFlight[2] = secondReq
|
||||
|
||||
doArchive(db.DefaultContext, zipReq)
|
||||
doArchive(db.DefaultContext, tgzReq)
|
||||
doArchive(db.DefaultContext, secondReq)
|
||||
doArchive(t.Context(), zipReq)
|
||||
doArchive(t.Context(), tgzReq)
|
||||
doArchive(t.Context(), secondReq)
|
||||
|
||||
// Make sure sending an unprocessed request through doesn't affect the queue
|
||||
// count.
|
||||
doArchive(db.DefaultContext, zipReq)
|
||||
doArchive(t.Context(), zipReq)
|
||||
|
||||
// Sleep two seconds to make sure the queue doesn't change.
|
||||
time.Sleep(2 * time.Second)
|
||||
@@ -100,7 +99,7 @@ func TestArchive_Basic(t *testing.T) {
|
||||
// We still have the other three stalled at completion, waiting to remove
|
||||
// from archiveInProgress. Try to submit this new one before its
|
||||
// predecessor has cleared out of the queue.
|
||||
doArchive(db.DefaultContext, zipReq2)
|
||||
doArchive(t.Context(), zipReq2)
|
||||
|
||||
// Now we'll submit a request and TimedWaitForCompletion twice, before and
|
||||
// after we release it. We should trigger both the timeout and non-timeout
|
||||
@@ -108,7 +107,7 @@ func TestArchive_Basic(t *testing.T) {
|
||||
timedReq, err := NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, secondCommit+".tar.gz")
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, timedReq)
|
||||
doArchive(db.DefaultContext, timedReq)
|
||||
doArchive(t.Context(), timedReq)
|
||||
|
||||
zipReq2, err = NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
|
||||
assert.NoError(t, err)
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"image/png"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/avatar"
|
||||
@@ -26,7 +25,7 @@ func TestUploadAvatar(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
|
||||
|
||||
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
|
||||
err := UploadAvatar(t.Context(), repo, buff.Bytes())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, avatar.HashAvatar(10, buff.Bytes()), repo.Avatar)
|
||||
}
|
||||
@@ -40,7 +39,7 @@ func TestUploadBigAvatar(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
|
||||
|
||||
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
|
||||
err := UploadAvatar(t.Context(), repo, buff.Bytes())
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
@@ -53,10 +52,10 @@ func TestDeleteAvatar(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10})
|
||||
|
||||
err := UploadAvatar(db.DefaultContext, repo, buff.Bytes())
|
||||
err := UploadAvatar(t.Context(), repo, buff.Bytes())
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = DeleteAvatar(db.DefaultContext, repo)
|
||||
err = DeleteAvatar(t.Context(), repo)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Empty(t, repo.Avatar)
|
||||
@@ -65,7 +64,7 @@ func TestDeleteAvatar(t *testing.T) {
|
||||
func TestGenerateAvatar(t *testing.T) {
|
||||
templateRepo := &repo_model.Repository{ID: 10, Avatar: "a"}
|
||||
generateRepo := &repo_model.Repository{ID: 11}
|
||||
_ = generateAvatar(db.DefaultContext, templateRepo, generateRepo)
|
||||
_ = generateAvatar(t.Context(), templateRepo, generateRepo)
|
||||
assert.NotEmpty(t, generateRepo.Avatar)
|
||||
assert.NotEqual(t, templateRepo.Avatar, generateRepo.Avatar)
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package repository
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/perm"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -20,9 +19,9 @@ func TestRepository_AddCollaborator(t *testing.T) {
|
||||
|
||||
testSuccess := func(repoID, userID int64) {
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
||||
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
|
||||
assert.NoError(t, repo.LoadOwner(t.Context()))
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
|
||||
assert.NoError(t, AddOrUpdateCollaborator(db.DefaultContext, repo, user, perm.AccessModeWrite))
|
||||
assert.NoError(t, AddOrUpdateCollaborator(t.Context(), repo, user, perm.AccessModeWrite))
|
||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID}, &user_model.User{ID: userID})
|
||||
}
|
||||
testSuccess(1, 4)
|
||||
@@ -36,11 +35,11 @@ func TestRepository_DeleteCollaboration(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
|
||||
|
||||
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
|
||||
assert.NoError(t, DeleteCollaboration(db.DefaultContext, repo, user))
|
||||
assert.NoError(t, repo.LoadOwner(t.Context()))
|
||||
assert.NoError(t, DeleteCollaboration(t.Context(), repo, user))
|
||||
unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: user.ID})
|
||||
|
||||
assert.NoError(t, DeleteCollaboration(db.DefaultContext, repo, user))
|
||||
assert.NoError(t, DeleteCollaboration(t.Context(), repo, user))
|
||||
unittest.AssertNotExistsBean(t, &repo_model.Collaboration{RepoID: repo.ID, UserID: user.ID})
|
||||
|
||||
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repo.ID})
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
@@ -20,7 +19,7 @@ func TestRepository_ContributorsGraph(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
|
||||
assert.NoError(t, repo.LoadOwner(t.Context()))
|
||||
mockCache, err := cache.NewStringCache(setting.Cache{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/options"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
@@ -459,7 +460,7 @@ func createRepositoryInDB(ctx context.Context, doer, u *user_model.User, repo *r
|
||||
}
|
||||
|
||||
func cleanupRepository(repoID int64) {
|
||||
if errDelete := DeleteRepositoryDirectly(db.DefaultContext, repoID); errDelete != nil {
|
||||
if errDelete := DeleteRepositoryDirectly(graceful.GetManager().ShutdownContext(), repoID); errDelete != nil {
|
||||
log.Error("cleanupRepository failed: %v", errDelete)
|
||||
// add system notice
|
||||
if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when cleanup repository: %v", errDelete); err != nil {
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
@@ -34,14 +33,14 @@ func TestCreateRepositoryDirectly(t *testing.T) {
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: user2.Name, Name: createdRepo.Name})
|
||||
|
||||
err = DeleteRepositoryDirectly(db.DefaultContext, createdRepo.ID)
|
||||
err = DeleteRepositoryDirectly(t.Context(), createdRepo.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// a failed creating because some mock data
|
||||
// create the repository directory so that the creation will fail after database record created.
|
||||
assert.NoError(t, os.MkdirAll(repo_model.RepoPath(user2.Name, createdRepo.Name), os.ModePerm))
|
||||
|
||||
createdRepo2, err := CreateRepositoryDirectly(db.DefaultContext, user2, user2, CreateRepoOptions{
|
||||
createdRepo2, err := CreateRepositoryDirectly(t.Context(), user2, user2, CreateRepoOptions{
|
||||
Name: "created-repo",
|
||||
}, true)
|
||||
assert.Nil(t, createdRepo2)
|
||||
|
@@ -24,6 +24,7 @@ import (
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
actions_module "code.gitea.io/gitea/modules/actions"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
@@ -309,8 +310,7 @@ func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams
|
||||
// Remove repository files.
|
||||
if err := gitrepo.DeleteRepository(ctx, repo); err != nil {
|
||||
desc := fmt.Sprintf("Delete repository files [%s]: %v", repo.FullName(), err)
|
||||
// Note we use the db.DefaultContext here rather than passing in a context as the context may be cancelled
|
||||
if err = system_model.CreateNotice(db.DefaultContext, system_model.NoticeRepository, desc); err != nil {
|
||||
if err = system_model.CreateNotice(graceful.GetManager().ShutdownContext(), system_model.NoticeRepository, desc); err != nil {
|
||||
log.Error("CreateRepositoryNotice: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package repository_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -21,7 +20,7 @@ func TestTeam_HasRepository(t *testing.T) {
|
||||
|
||||
test := func(teamID, repoID int64, expected bool) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.Equal(t, expected, repo_service.HasRepository(db.DefaultContext, team, repoID))
|
||||
assert.Equal(t, expected, repo_service.HasRepository(t.Context(), team, repoID))
|
||||
}
|
||||
test(1, 1, false)
|
||||
test(1, 3, true)
|
||||
@@ -37,7 +36,7 @@ func TestTeam_RemoveRepository(t *testing.T) {
|
||||
|
||||
testSuccess := func(teamID, repoID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, repo_service.RemoveRepositoryFromTeam(db.DefaultContext, team, repoID))
|
||||
assert.NoError(t, repo_service.RemoveRepositoryFromTeam(t.Context(), team, repoID))
|
||||
unittest.AssertNotExistsBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
|
||||
}
|
||||
@@ -51,5 +50,5 @@ func TestDeleteOwnerRepositoriesDirectly(t *testing.T) {
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(db.DefaultContext, user))
|
||||
assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(t.Context(), user))
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
@@ -68,14 +67,14 @@ func TestForkRepositoryCleanup(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
|
||||
err = DeleteRepositoryDirectly(db.DefaultContext, fork.ID)
|
||||
err = DeleteRepositoryDirectly(t.Context(), fork.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// a failed creating because some mock data
|
||||
// create the repository directory so that the creation will fail after database record created.
|
||||
assert.NoError(t, os.MkdirAll(repo_model.RepoPath(user2.Name, "test"), os.ModePerm))
|
||||
|
||||
fork2, err := ForkRepository(db.DefaultContext, user2, user2, ForkRepoOptions{
|
||||
fork2, err := ForkRepository(t.Context(), user2, user2, ForkRepoOptions{
|
||||
BaseRepo: repo10,
|
||||
Name: "test",
|
||||
})
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -27,7 +26,7 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
|
||||
err := storage.Init()
|
||||
assert.NoError(t, err)
|
||||
|
||||
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1")
|
||||
repo, err := repo_model.GetRepositoryByOwnerAndName(t.Context(), "user2", "repo1")
|
||||
assert.NoError(t, err)
|
||||
|
||||
// add lfs object
|
||||
@@ -43,7 +42,7 @@ func TestGarbageCollectLFSMetaObjects(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// lfs meta has been deleted
|
||||
_, err = git_model.GetLFSMetaObjectByOid(db.DefaultContext, repo.ID, lfsOid)
|
||||
_, err = git_model.GetLFSMetaObjectByOid(t.Context(), repo.ID, lfsOid)
|
||||
assert.ErrorIs(t, err, git_model.ErrLFSObjectNotExist)
|
||||
}
|
||||
|
||||
@@ -51,7 +50,7 @@ func storeObjectInRepo(t *testing.T, repositoryID int64, content *[]byte) string
|
||||
pointer, err := lfs.GeneratePointer(bytes.NewReader(*content))
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = git_model.NewLFSMetaObject(db.DefaultContext, repositoryID, pointer)
|
||||
_, err = git_model.NewLFSMetaObject(t.Context(), repositoryID, pointer)
|
||||
assert.NoError(t, err)
|
||||
contentStore := lfs.NewContentStore()
|
||||
exist, err := contentStore.Exists(pointer)
|
||||
|
@@ -6,7 +6,6 @@ package repository
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -20,7 +19,7 @@ func TestTeam_AddRepository(t *testing.T) {
|
||||
testSuccess := func(teamID, repoID int64) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
|
||||
assert.NoError(t, TeamAddRepository(db.DefaultContext, team, repo))
|
||||
assert.NoError(t, TeamAddRepository(t.Context(), team, repo))
|
||||
unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
|
||||
}
|
||||
@@ -29,6 +28,6 @@ func TestTeam_AddRepository(t *testing.T) {
|
||||
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
assert.Error(t, TeamAddRepository(db.DefaultContext, team, repo))
|
||||
assert.Error(t, TeamAddRepository(t.Context(), team, repo))
|
||||
unittest.CheckConsistencyFor(t, &organization.Team{ID: 1}, &repo_model.Repository{ID: 1})
|
||||
}
|
||||
|
@@ -30,9 +30,9 @@ func TestLinkedRepository(t *testing.T) {
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
attach, err := repo_model.GetAttachmentByID(db.DefaultContext, tc.attachID)
|
||||
attach, err := repo_model.GetAttachmentByID(t.Context(), tc.attachID)
|
||||
assert.NoError(t, err)
|
||||
repo, unitType, err := LinkedRepository(db.DefaultContext, attach)
|
||||
repo, unitType, err := LinkedRepository(t.Context(), attach)
|
||||
assert.NoError(t, err)
|
||||
if tc.expectedRepo != nil {
|
||||
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
|
||||
@@ -46,17 +46,17 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// Get sample repo and change visibility
|
||||
repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 9)
|
||||
repo, err := repo_model.GetRepositoryByID(t.Context(), 9)
|
||||
assert.NoError(t, err)
|
||||
repo.IsPrivate = true
|
||||
|
||||
// Update it
|
||||
err = updateRepository(db.DefaultContext, repo, true)
|
||||
err = updateRepository(t.Context(), repo, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check visibility of action has become private
|
||||
act := activities_model.Action{}
|
||||
_, err = db.GetEngine(db.DefaultContext).ID(3).Get(&act)
|
||||
_, err = db.GetEngine(t.Context()).ID(3).Get(&act)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, act.IsPrivate)
|
||||
|
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/organization"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -39,10 +38,10 @@ func TestTransferOwnership(t *testing.T) {
|
||||
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
|
||||
assert.NoError(t, repo.LoadOwner(t.Context()))
|
||||
repoTransfer := unittest.AssertExistsAndLoadBean(t, &repo_model.RepoTransfer{ID: 1})
|
||||
assert.NoError(t, repoTransfer.LoadAttributes(db.DefaultContext))
|
||||
assert.NoError(t, AcceptTransferOwnership(db.DefaultContext, repo, doer))
|
||||
assert.NoError(t, repoTransfer.LoadAttributes(t.Context()))
|
||||
assert.NoError(t, AcceptTransferOwnership(t.Context(), repo, doer))
|
||||
|
||||
transferredRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||
assert.EqualValues(t, 1, transferredRepo.OwnerID) // repo_transfer.yml id=1
|
||||
@@ -70,15 +69,15 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
recipient := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
assert.NoError(t, repo.LoadOwner(db.DefaultContext))
|
||||
assert.NoError(t, repo.LoadOwner(t.Context()))
|
||||
|
||||
hasAccess, err := access_model.HasAnyUnitAccess(db.DefaultContext, recipient.ID, repo)
|
||||
hasAccess, err := access_model.HasAnyUnitAccess(t.Context(), recipient.ID, repo)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, hasAccess)
|
||||
|
||||
assert.NoError(t, StartRepositoryTransfer(db.DefaultContext, doer, recipient, repo, nil))
|
||||
assert.NoError(t, StartRepositoryTransfer(t.Context(), doer, recipient, repo, nil))
|
||||
|
||||
hasAccess, err = access_model.HasAnyUnitAccess(db.DefaultContext, recipient.ID, repo)
|
||||
hasAccess, err = access_model.HasAnyUnitAccess(t.Context(), recipient.ID, repo)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, hasAccess)
|
||||
|
||||
@@ -91,41 +90,41 @@ func TestRepositoryTransfer(t *testing.T) {
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||
|
||||
transfer, err := repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||
transfer, err := repo_model.GetPendingRepositoryTransfer(t.Context(), repo)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, transfer)
|
||||
|
||||
// Cancel transfer
|
||||
assert.NoError(t, CancelRepositoryTransfer(db.DefaultContext, transfer, doer))
|
||||
assert.NoError(t, CancelRepositoryTransfer(t.Context(), transfer, doer))
|
||||
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(t.Context(), repo)
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, transfer)
|
||||
assert.True(t, repo_model.IsErrNoPendingTransfer(err))
|
||||
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
assert.NoError(t, repo_model.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
|
||||
assert.NoError(t, repo_model.CreatePendingRepositoryTransfer(t.Context(), doer, user2, repo.ID, nil))
|
||||
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(t.Context(), repo)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, transfer.LoadAttributes(db.DefaultContext))
|
||||
assert.NoError(t, transfer.LoadAttributes(t.Context()))
|
||||
assert.Equal(t, "user2", transfer.Recipient.Name)
|
||||
|
||||
org6 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// Only transfer can be started at any given time
|
||||
err = repo_model.CreatePendingRepositoryTransfer(db.DefaultContext, doer, org6, repo.ID, nil)
|
||||
err = repo_model.CreatePendingRepositoryTransfer(t.Context(), doer, org6, repo.ID, nil)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, repo_model.IsErrRepoTransferInProgress(err))
|
||||
|
||||
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
// Unknown user, transfer non-existent transfer repo id = 2
|
||||
err = repo_model.CreatePendingRepositoryTransfer(db.DefaultContext, doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo2.ID, nil)
|
||||
err = repo_model.CreatePendingRepositoryTransfer(t.Context(), doer, &user_model.User{ID: 1000, LowerName: "user1000"}, repo2.ID, nil)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Reject transfer
|
||||
err = RejectRepositoryTransfer(db.DefaultContext, repo2, doer)
|
||||
err = RejectRepositoryTransfer(t.Context(), repo2, doer)
|
||||
assert.True(t, repo_model.IsErrNoPendingTransfer(err))
|
||||
}
|
||||
|
||||
@@ -139,29 +138,29 @@ func TestRepositoryTransferRejection(t *testing.T) {
|
||||
doerAdmin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
|
||||
|
||||
transfer, err := repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||
transfer, err := repo_model.GetPendingRepositoryTransfer(t.Context(), repo)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, transfer)
|
||||
require.NoError(t, transfer.LoadRecipient(db.DefaultContext))
|
||||
require.NoError(t, transfer.LoadRecipient(t.Context()))
|
||||
|
||||
require.True(t, doerAdmin.CanCreateRepoIn(transfer.Recipient)) // admin is not subject to limits
|
||||
|
||||
// Administrator should not be affected by the limits so transfer should be successful
|
||||
assert.NoError(t, AcceptTransferOwnership(db.DefaultContext, repo, doerAdmin))
|
||||
assert.NoError(t, AcceptTransferOwnership(t.Context(), repo, doerAdmin))
|
||||
|
||||
// Non admin user case
|
||||
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10})
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21})
|
||||
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||
transfer, err = repo_model.GetPendingRepositoryTransfer(t.Context(), repo)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, transfer)
|
||||
require.NoError(t, transfer.LoadRecipient(db.DefaultContext))
|
||||
require.NoError(t, transfer.LoadRecipient(t.Context()))
|
||||
|
||||
require.False(t, doer.CanCreateRepoIn(transfer.Recipient)) // regular user is subject to limits
|
||||
|
||||
// Cannot accept because of the limit
|
||||
err = AcceptTransferOwnership(db.DefaultContext, repo, doer)
|
||||
err = AcceptTransferOwnership(t.Context(), repo, doer)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, IsRepositoryLimitReached(err))
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
admin_model "code.gitea.io/gitea/models/admin"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
@@ -50,7 +49,7 @@ func Init() error {
|
||||
|
||||
func handler(items ...*admin_model.Task) []*admin_model.Task {
|
||||
for _, task := range items {
|
||||
if err := Run(db.DefaultContext, task); err != nil {
|
||||
if err := Run(graceful.GetManager().ShutdownContext(), task); err != nil {
|
||||
log.Error("Run task failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ func NewNotifier() notify_service.Notifier {
|
||||
|
||||
func handler(items ...issueNotificationOpts) []issueNotificationOpts {
|
||||
for _, opts := range items {
|
||||
if err := activities_model.CreateOrUpdateIssueNotifications(db.DefaultContext, opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
|
||||
if err := activities_model.CreateOrUpdateIssueNotifications(graceful.GetManager().ShutdownContext(), opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
|
||||
log.Error("Was unable to create issue notification: %v", err)
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package user
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
@@ -23,23 +22,23 @@ func TestCanBlockUser(t *testing.T) {
|
||||
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
|
||||
// Doer can't self block
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user1, user2, user1))
|
||||
assert.False(t, CanBlockUser(t.Context(), user1, user2, user1))
|
||||
// Blocker can't be blockee
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user1, user2, user2))
|
||||
assert.False(t, CanBlockUser(t.Context(), user1, user2, user2))
|
||||
// Can't block already blocked user
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user1, user2, user29))
|
||||
assert.False(t, CanBlockUser(t.Context(), user1, user2, user29))
|
||||
// Blockee can't be an organization
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user1, user2, org3))
|
||||
assert.False(t, CanBlockUser(t.Context(), user1, user2, org3))
|
||||
// Doer must be blocker or admin
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user2, user4, user29))
|
||||
assert.False(t, CanBlockUser(t.Context(), user2, user4, user29))
|
||||
// Organization can't block a member
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user1, org3, user4))
|
||||
assert.False(t, CanBlockUser(t.Context(), user1, org3, user4))
|
||||
// Doer must be organization owner or admin if blocker is an organization
|
||||
assert.False(t, CanBlockUser(db.DefaultContext, user4, org3, user2))
|
||||
assert.False(t, CanBlockUser(t.Context(), user4, org3, user2))
|
||||
|
||||
assert.True(t, CanBlockUser(db.DefaultContext, user1, user2, user4))
|
||||
assert.True(t, CanBlockUser(db.DefaultContext, user2, user2, user4))
|
||||
assert.True(t, CanBlockUser(db.DefaultContext, user2, org3, user29))
|
||||
assert.True(t, CanBlockUser(t.Context(), user1, user2, user4))
|
||||
assert.True(t, CanBlockUser(t.Context(), user2, user2, user4))
|
||||
assert.True(t, CanBlockUser(t.Context(), user2, org3, user29))
|
||||
}
|
||||
|
||||
func TestCanUnblockUser(t *testing.T) {
|
||||
@@ -52,15 +51,15 @@ func TestCanUnblockUser(t *testing.T) {
|
||||
org17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 17})
|
||||
|
||||
// Doer can't self unblock
|
||||
assert.False(t, CanUnblockUser(db.DefaultContext, user1, user2, user1))
|
||||
assert.False(t, CanUnblockUser(t.Context(), user1, user2, user1))
|
||||
// Can't unblock not blocked user
|
||||
assert.False(t, CanUnblockUser(db.DefaultContext, user1, user2, user28))
|
||||
assert.False(t, CanUnblockUser(t.Context(), user1, user2, user28))
|
||||
// Doer must be blocker or admin
|
||||
assert.False(t, CanUnblockUser(db.DefaultContext, user28, user2, user29))
|
||||
assert.False(t, CanUnblockUser(t.Context(), user28, user2, user29))
|
||||
// Doer must be organization owner or admin if blocker is an organization
|
||||
assert.False(t, CanUnblockUser(db.DefaultContext, user2, org17, user28))
|
||||
assert.False(t, CanUnblockUser(t.Context(), user2, org17, user28))
|
||||
|
||||
assert.True(t, CanUnblockUser(db.DefaultContext, user1, user2, user29))
|
||||
assert.True(t, CanUnblockUser(db.DefaultContext, user2, user2, user29))
|
||||
assert.True(t, CanUnblockUser(db.DefaultContext, user1, org17, user28))
|
||||
assert.True(t, CanUnblockUser(t.Context(), user1, user2, user29))
|
||||
assert.True(t, CanUnblockUser(t.Context(), user2, user2, user29))
|
||||
assert.True(t, CanUnblockUser(t.Context(), user1, org17, user28))
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package user
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
organization_model "code.gitea.io/gitea/models/organization"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -21,23 +20,23 @@ func TestAdminAddOrSetPrimaryEmailAddress(t *testing.T) {
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 27})
|
||||
|
||||
emails, err := user_model.GetEmailAddresses(db.DefaultContext, user.ID)
|
||||
emails, err := user_model.GetEmailAddresses(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, emails, 1)
|
||||
|
||||
primary, err := user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err := user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, "new-primary@example.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(db.DefaultContext, user, "new-primary@example.com"))
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(t.Context(), user, "new-primary@example.com"))
|
||||
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "new-primary@example.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
emails, err = user_model.GetEmailAddresses(db.DefaultContext, user.ID)
|
||||
emails, err = user_model.GetEmailAddresses(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, emails, 2)
|
||||
|
||||
@@ -46,21 +45,21 @@ func TestAdminAddOrSetPrimaryEmailAddress(t *testing.T) {
|
||||
setting.Service.EmailDomainAllowList = []glob.Glob{}
|
||||
}()
|
||||
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(db.DefaultContext, user, "new-primary2@example2.com"))
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(t.Context(), user, "new-primary2@example2.com"))
|
||||
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "new-primary2@example2.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(db.DefaultContext, user, "user27@example.com"))
|
||||
assert.NoError(t, AdminAddOrSetPrimaryEmailAddress(t.Context(), user, "user27@example.com"))
|
||||
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "user27@example.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
emails, err = user_model.GetEmailAddresses(db.DefaultContext, user.ID)
|
||||
emails, err = user_model.GetEmailAddresses(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, emails, 3)
|
||||
}
|
||||
@@ -71,27 +70,27 @@ func TestReplacePrimaryEmailAddress(t *testing.T) {
|
||||
t.Run("User", func(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13})
|
||||
|
||||
emails, err := user_model.GetEmailAddresses(db.DefaultContext, user.ID)
|
||||
emails, err := user_model.GetEmailAddresses(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, emails, 1)
|
||||
|
||||
primary, err := user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err := user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEqual(t, "primary-13@example.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(db.DefaultContext, user, "primary-13@example.com"))
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(t.Context(), user, "primary-13@example.com"))
|
||||
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(db.DefaultContext, user.ID)
|
||||
primary, err = user_model.GetPrimaryEmailAddressOfUser(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "primary-13@example.com", primary.Email)
|
||||
assert.Equal(t, user.Email, primary.Email)
|
||||
|
||||
emails, err = user_model.GetEmailAddresses(db.DefaultContext, user.ID)
|
||||
emails, err = user_model.GetEmailAddresses(t.Context(), user.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, emails, 1)
|
||||
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(db.DefaultContext, user, "primary-13@example.com"))
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(t.Context(), user, "primary-13@example.com"))
|
||||
})
|
||||
|
||||
t.Run("Organization", func(t *testing.T) {
|
||||
@@ -99,7 +98,7 @@ func TestReplacePrimaryEmailAddress(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "org3@example.com", org.Email)
|
||||
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(db.DefaultContext, org.AsUser(), "primary-org@example.com"))
|
||||
assert.NoError(t, ReplacePrimaryEmailAddress(t.Context(), org.AsUser(), "primary-org@example.com"))
|
||||
|
||||
assert.Equal(t, "primary-org@example.com", org.Email)
|
||||
})
|
||||
@@ -110,13 +109,13 @@ func TestAddEmailAddresses(t *testing.T) {
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
assert.Error(t, AddEmailAddresses(db.DefaultContext, user, []string{" invalid email "}))
|
||||
assert.Error(t, AddEmailAddresses(t.Context(), user, []string{" invalid email "}))
|
||||
|
||||
emails := []string{"user1234@example.com", "user5678@example.com"}
|
||||
|
||||
assert.NoError(t, AddEmailAddresses(db.DefaultContext, user, emails))
|
||||
assert.NoError(t, AddEmailAddresses(t.Context(), user, emails))
|
||||
|
||||
err := AddEmailAddresses(db.DefaultContext, user, emails)
|
||||
err := AddEmailAddresses(t.Context(), user, emails)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, user_model.IsErrEmailAlreadyUsed(err))
|
||||
}
|
||||
@@ -128,16 +127,16 @@ func TestDeleteEmailAddresses(t *testing.T) {
|
||||
|
||||
emails := []string{"user2-2@example.com"}
|
||||
|
||||
err := DeleteEmailAddresses(db.DefaultContext, user, emails)
|
||||
err := DeleteEmailAddresses(t.Context(), user, emails)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = DeleteEmailAddresses(db.DefaultContext, user, emails)
|
||||
err = DeleteEmailAddresses(t.Context(), user, emails)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, user_model.IsErrEmailAddressNotExist(err))
|
||||
|
||||
emails = []string{"user2@example.com"}
|
||||
|
||||
err = DeleteEmailAddresses(db.DefaultContext, user, emails)
|
||||
err = DeleteEmailAddresses(t.Context(), user, emails)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, user_model.IsErrPrimaryEmailCannotDelete(err))
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ package user
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
password_module "code.gitea.io/gitea/modules/auth/password"
|
||||
@@ -21,11 +20,11 @@ func TestUpdateUser(t *testing.T) {
|
||||
|
||||
admin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
assert.Error(t, UpdateUser(db.DefaultContext, admin, &UpdateOptions{
|
||||
assert.Error(t, UpdateUser(t.Context(), admin, &UpdateOptions{
|
||||
IsAdmin: UpdateOptionFieldFromValue(false),
|
||||
}))
|
||||
|
||||
assert.NoError(t, UpdateUser(db.DefaultContext, admin, &UpdateOptions{
|
||||
assert.NoError(t, UpdateUser(t.Context(), admin, &UpdateOptions{
|
||||
IsAdmin: UpdateOptionFieldFromSync(false),
|
||||
}))
|
||||
|
||||
@@ -52,7 +51,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
EmailNotificationsPreference: optional.Some("disabled"),
|
||||
SetLastLogin: true,
|
||||
}
|
||||
assert.NoError(t, UpdateUser(db.DefaultContext, user, opts))
|
||||
assert.NoError(t, UpdateUser(t.Context(), user, opts))
|
||||
|
||||
assert.Equal(t, opts.KeepEmailPrivate.Value(), user.KeepEmailPrivate)
|
||||
assert.Equal(t, opts.FullName.Value(), user.FullName)
|
||||
@@ -100,12 +99,12 @@ func TestUpdateAuth(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 28})
|
||||
userCopy := *user
|
||||
|
||||
assert.NoError(t, UpdateAuth(db.DefaultContext, user, &UpdateAuthOptions{
|
||||
assert.NoError(t, UpdateAuth(t.Context(), user, &UpdateAuthOptions{
|
||||
LoginName: optional.Some("new-login"),
|
||||
}))
|
||||
assert.Equal(t, "new-login", user.LoginName)
|
||||
|
||||
assert.NoError(t, UpdateAuth(db.DefaultContext, user, &UpdateAuthOptions{
|
||||
assert.NoError(t, UpdateAuth(t.Context(), user, &UpdateAuthOptions{
|
||||
Password: optional.Some("%$DRZUVB576tfzgu"),
|
||||
MustChangePassword: optional.Some(true),
|
||||
}))
|
||||
@@ -113,12 +112,12 @@ func TestUpdateAuth(t *testing.T) {
|
||||
assert.NotEqual(t, userCopy.Passwd, user.Passwd)
|
||||
assert.NotEqual(t, userCopy.Salt, user.Salt)
|
||||
|
||||
assert.NoError(t, UpdateAuth(db.DefaultContext, user, &UpdateAuthOptions{
|
||||
assert.NoError(t, UpdateAuth(t.Context(), user, &UpdateAuthOptions{
|
||||
ProhibitLogin: optional.Some(true),
|
||||
}))
|
||||
assert.True(t, user.ProhibitLogin)
|
||||
|
||||
assert.ErrorIs(t, UpdateAuth(db.DefaultContext, user, &UpdateAuthOptions{
|
||||
assert.ErrorIs(t, UpdateAuth(t.Context(), user, &UpdateAuthOptions{
|
||||
Password: optional.Some("aaaa"),
|
||||
}), password_module.ErrMinLength)
|
||||
}
|
||||
|
@@ -32,24 +32,24 @@ func TestDeleteUser(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
|
||||
|
||||
ownedRepos := make([]*repo_model.Repository, 0, 10)
|
||||
assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&ownedRepos, &repo_model.Repository{OwnerID: userID}))
|
||||
assert.NoError(t, db.GetEngine(t.Context()).Find(&ownedRepos, &repo_model.Repository{OwnerID: userID}))
|
||||
if len(ownedRepos) > 0 {
|
||||
err := DeleteUser(db.DefaultContext, user, false)
|
||||
err := DeleteUser(t.Context(), user, false)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, repo_model.IsErrUserOwnRepos(err))
|
||||
return
|
||||
}
|
||||
|
||||
orgUsers := make([]*organization.OrgUser, 0, 10)
|
||||
assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&orgUsers, &organization.OrgUser{UID: userID}))
|
||||
assert.NoError(t, db.GetEngine(t.Context()).Find(&orgUsers, &organization.OrgUser{UID: userID}))
|
||||
for _, orgUser := range orgUsers {
|
||||
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: orgUser.OrgID})
|
||||
if err := org_service.RemoveOrgUser(db.DefaultContext, org, user); err != nil {
|
||||
if err := org_service.RemoveOrgUser(t.Context(), org, user); err != nil {
|
||||
assert.True(t, organization.IsErrLastOrgOwner(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
assert.NoError(t, DeleteUser(db.DefaultContext, user, false))
|
||||
assert.NoError(t, DeleteUser(t.Context(), user, false))
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
|
||||
unittest.CheckConsistencyFor(t, &user_model.User{}, &repo_model.Repository{})
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func TestDeleteUser(t *testing.T) {
|
||||
test(11)
|
||||
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
assert.Error(t, DeleteUser(db.DefaultContext, org, false))
|
||||
assert.Error(t, DeleteUser(t.Context(), org, false))
|
||||
}
|
||||
|
||||
func TestPurgeUser(t *testing.T) {
|
||||
@@ -67,7 +67,7 @@ func TestPurgeUser(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
|
||||
|
||||
err := DeleteUser(db.DefaultContext, user, true)
|
||||
err := DeleteUser(t.Context(), user, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{ID: userID})
|
||||
@@ -79,7 +79,7 @@ func TestPurgeUser(t *testing.T) {
|
||||
test(11)
|
||||
|
||||
org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3})
|
||||
assert.Error(t, DeleteUser(db.DefaultContext, org, false))
|
||||
assert.Error(t, DeleteUser(t.Context(), org, false))
|
||||
}
|
||||
|
||||
func TestCreateUser(t *testing.T) {
|
||||
@@ -92,9 +92,9 @@ func TestCreateUser(t *testing.T) {
|
||||
MustChangePassword: false,
|
||||
}
|
||||
|
||||
assert.NoError(t, user_model.CreateUser(db.DefaultContext, user, &user_model.Meta{}))
|
||||
assert.NoError(t, user_model.CreateUser(t.Context(), user, &user_model.Meta{}))
|
||||
|
||||
assert.NoError(t, DeleteUser(db.DefaultContext, user, false))
|
||||
assert.NoError(t, DeleteUser(t.Context(), user, false))
|
||||
}
|
||||
|
||||
func TestRenameUser(t *testing.T) {
|
||||
@@ -106,18 +106,18 @@ func TestRenameUser(t *testing.T) {
|
||||
Type: user_model.UserTypeIndividual,
|
||||
LoginType: auth.OAuth2,
|
||||
}
|
||||
assert.ErrorIs(t, RenameUser(db.DefaultContext, u, "user_rename"), user_model.ErrUserIsNotLocal{})
|
||||
assert.ErrorIs(t, RenameUser(t.Context(), u, "user_rename"), user_model.ErrUserIsNotLocal{})
|
||||
})
|
||||
|
||||
t.Run("Same username", func(t *testing.T) {
|
||||
assert.NoError(t, RenameUser(db.DefaultContext, user, user.Name))
|
||||
assert.NoError(t, RenameUser(t.Context(), user, user.Name))
|
||||
})
|
||||
|
||||
t.Run("Non usable username", func(t *testing.T) {
|
||||
usernames := []string{"--diff", ".well-known", "gitea-actions", "aaa.atom", "aa.png"}
|
||||
for _, username := range usernames {
|
||||
assert.Error(t, user_model.IsUsableUsername(username), "non-usable username: %s", username)
|
||||
assert.Error(t, RenameUser(db.DefaultContext, user, username), "non-usable username: %s", username)
|
||||
assert.Error(t, RenameUser(t.Context(), user, username), "non-usable username: %s", username)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestRenameUser(t *testing.T) {
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{ID: user.ID, Name: caps})
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: user.Name})
|
||||
|
||||
assert.NoError(t, RenameUser(db.DefaultContext, user, caps))
|
||||
assert.NoError(t, RenameUser(t.Context(), user, caps))
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: caps})
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: caps})
|
||||
@@ -135,20 +135,20 @@ func TestRenameUser(t *testing.T) {
|
||||
t.Run("Already exists", func(t *testing.T) {
|
||||
existUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.Name), user_model.ErrUserAlreadyExist{Name: existUser.Name})
|
||||
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.LowerName), user_model.ErrUserAlreadyExist{Name: existUser.LowerName})
|
||||
assert.ErrorIs(t, RenameUser(t.Context(), user, existUser.Name), user_model.ErrUserAlreadyExist{Name: existUser.Name})
|
||||
assert.ErrorIs(t, RenameUser(t.Context(), user, existUser.LowerName), user_model.ErrUserAlreadyExist{Name: existUser.LowerName})
|
||||
newUsername := fmt.Sprintf("uSEr%d", existUser.ID)
|
||||
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, newUsername), user_model.ErrUserAlreadyExist{Name: newUsername})
|
||||
assert.ErrorIs(t, RenameUser(t.Context(), user, newUsername), user_model.ErrUserAlreadyExist{Name: newUsername})
|
||||
})
|
||||
|
||||
t.Run("Normal", func(t *testing.T) {
|
||||
oldUsername := user.Name
|
||||
newUsername := "User_Rename"
|
||||
|
||||
assert.NoError(t, RenameUser(db.DefaultContext, user, newUsername))
|
||||
assert.NoError(t, RenameUser(t.Context(), user, newUsername))
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: newUsername, LowerName: strings.ToLower(newUsername)})
|
||||
|
||||
redirectUID, err := user_model.LookupUserRedirect(db.DefaultContext, oldUsername)
|
||||
redirectUID, err := user_model.LookupUserRedirect(t.Context(), oldUsername)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, user.ID, redirectUID)
|
||||
|
||||
@@ -175,24 +175,24 @@ func TestCreateUser_Issue5882(t *testing.T) {
|
||||
for _, v := range tt {
|
||||
setting.Admin.DisableRegularOrgCreation = v.disableOrgCreation
|
||||
|
||||
assert.NoError(t, user_model.CreateUser(db.DefaultContext, v.user, &user_model.Meta{}))
|
||||
assert.NoError(t, user_model.CreateUser(t.Context(), v.user, &user_model.Meta{}))
|
||||
|
||||
u, err := user_model.GetUserByEmail(db.DefaultContext, v.user.Email)
|
||||
u, err := user_model.GetUserByEmail(t.Context(), v.user.Email)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, !u.AllowCreateOrganization, v.disableOrgCreation)
|
||||
|
||||
assert.NoError(t, DeleteUser(db.DefaultContext, v.user, false))
|
||||
assert.NoError(t, DeleteUser(t.Context(), v.user, false))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteInactiveUsers(t *testing.T) {
|
||||
addUser := func(name, email string, createdUnix timeutil.TimeStamp, active bool) {
|
||||
inactiveUser := &user_model.User{Name: name, LowerName: strings.ToLower(name), Email: email, CreatedUnix: createdUnix, IsActive: active}
|
||||
_, err := db.GetEngine(db.DefaultContext).NoAutoTime().Insert(inactiveUser)
|
||||
_, err := db.GetEngine(t.Context()).NoAutoTime().Insert(inactiveUser)
|
||||
assert.NoError(t, err)
|
||||
inactiveUserEmail := &user_model.EmailAddress{UID: inactiveUser.ID, IsPrimary: true, Email: email, LowerEmail: strings.ToLower(email), IsActivated: active}
|
||||
err = db.Insert(db.DefaultContext, inactiveUserEmail)
|
||||
err = db.Insert(t.Context(), inactiveUserEmail)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
addUser("user-inactive-10", "user-inactive-10@test.com", timeutil.TimeStampNow().Add(-600), false)
|
||||
@@ -201,7 +201,7 @@ func TestDeleteInactiveUsers(t *testing.T) {
|
||||
addUser("user-active-5", "user-active-5@test.com", timeutil.TimeStampNow().Add(-300), true)
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user-inactive-10"})
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user-inactive-10@test.com"})
|
||||
assert.NoError(t, DeleteInactiveUsers(db.DefaultContext, 8*time.Minute))
|
||||
assert.NoError(t, DeleteInactiveUsers(t.Context(), 8*time.Minute))
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: "user-inactive-10"})
|
||||
unittest.AssertNotExistsBean(t, &user_model.EmailAddress{Email: "user-inactive-10@test.com"})
|
||||
unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user-inactive-5"})
|
||||
|
@@ -12,7 +12,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
webhook_model "code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/hostmatcher"
|
||||
@@ -105,7 +104,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||
}
|
||||
err := hook.SetHeaderAuthorization("Bearer s3cr3t-t0ken")
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
assert.NoError(t, webhook_model.CreateWebhook(t.Context(), hook))
|
||||
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
@@ -113,7 +112,7 @@ func TestWebhookDeliverAuthorizationHeader(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
hookTask, err = webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
hookTask, err = webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
@@ -170,7 +169,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
ContentType: webhook_model.ContentTypeJSON,
|
||||
Meta: `{"message_type":0}`, // text
|
||||
}
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
assert.NoError(t, webhook_model.CreateWebhook(t.Context(), hook))
|
||||
|
||||
t.Run("Version 1", func(t *testing.T) {
|
||||
hookTask := &webhook_model.HookTask{
|
||||
@@ -180,7 +179,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
PayloadVersion: 1,
|
||||
}
|
||||
|
||||
hookTask, err := webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
hookTask, err := webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
@@ -206,7 +205,7 @@ func TestWebhookDeliverHookTask(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
hookTask, err = webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
hookTask, err = webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
@@ -266,7 +265,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||
URL: s.URL + "/" + typ,
|
||||
Meta: "{}",
|
||||
}
|
||||
assert.NoError(t, webhook_model.CreateWebhook(db.DefaultContext, hook))
|
||||
assert.NoError(t, webhook_model.CreateWebhook(t.Context(), hook))
|
||||
|
||||
hookTask := &webhook_model.HookTask{
|
||||
HookID: hook.ID,
|
||||
@@ -275,7 +274,7 @@ func TestWebhookDeliverSpecificTypes(t *testing.T) {
|
||||
PayloadVersion: 2,
|
||||
}
|
||||
|
||||
hookTask, err := webhook_model.CreateHookTask(db.DefaultContext, hookTask)
|
||||
hookTask, err := webhook_model.CreateHookTask(t.Context(), hookTask)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, hookTask)
|
||||
|
||||
|
@@ -6,7 +6,6 @@ package webhook
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
@@ -43,7 +42,7 @@ func TestPrepareWebhooks(t *testing.T) {
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertNotExistsBean(t, hookTask)
|
||||
}
|
||||
assert.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
|
||||
assert.NoError(t, PrepareWebhooks(t.Context(), EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||
}
|
||||
@@ -60,7 +59,7 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
|
||||
unittest.AssertNotExistsBean(t, hookTask)
|
||||
}
|
||||
// this test also ensures that * doesn't handle / in any special way (like shell would)
|
||||
assert.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791", Commits: []*api.PayloadCommit{{}}}))
|
||||
assert.NoError(t, PrepareWebhooks(t.Context(), EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791", Commits: []*api.PayloadCommit{{}}}))
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertExistsAndLoadBean(t, hookTask)
|
||||
}
|
||||
@@ -76,7 +75,7 @@ func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertNotExistsBean(t, hookTask)
|
||||
}
|
||||
assert.NoError(t, PrepareWebhooks(db.DefaultContext, EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
|
||||
assert.NoError(t, PrepareWebhooks(t.Context(), EventSource{Repository: repo}, webhook_module.HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
|
||||
|
||||
for _, hookTask := range hookTasks {
|
||||
unittest.AssertNotExistsBean(t, hookTask)
|
||||
@@ -88,6 +87,6 @@ func TestWebhookUserMail(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Service.NoReplyAddress, "no-reply.com")()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
assert.Equal(t, user.GetPlaceholderEmail(), convert.ToUser(db.DefaultContext, user, nil).Email)
|
||||
assert.Equal(t, user.Email, convert.ToUser(db.DefaultContext, user, user).Email)
|
||||
assert.Equal(t, user.GetPlaceholderEmail(), convert.ToUser(t.Context(), user, nil).Email)
|
||||
assert.Equal(t, user.Email, convert.ToUser(t.Context(), user, user).Email)
|
||||
}
|
||||
|
Reference in New Issue
Block a user