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:
@@ -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