diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-03-22 23:22:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 16:22:54 +0100 |
commit | 7a550b3af20dad94cf468012a6b817b43b91c1ba (patch) | |
tree | 1b836eabf8e911f35d0446c0cdad053cb3572c79 /services/mailer/mail_test.go | |
parent | 2b55422cd71b0b325f054646de5cebf39b72b502 (diff) | |
download | gitea-7a550b3af20dad94cf468012a6b817b43b91c1ba.tar.gz gitea-7a550b3af20dad94cf468012a6b817b43b91c1ba.zip |
Use `ctx` instead of `db.DefaultContext` in some packages(routers/services/modules) (#19163)
* Remove `db.DefaultContext` usage in routers, use `ctx` directly
* Use `ctx` directly if there is one, remove some `db.DefaultContext` in `services`
* Use ctx instead of db.DefaultContext for `cmd` and some `modules` packages
* fix incorrect context usage
Diffstat (limited to 'services/mailer/mail_test.go')
-rw-r--r-- | services/mailer/mail_test.go | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go index ba82fc6ff8..c06bae1b98 100644 --- a/services/mailer/mail_test.go +++ b/services/mailer/mail_test.go @@ -6,6 +6,7 @@ package mailer import ( "bytes" + "context" "fmt" "html/template" "strings" @@ -70,7 +71,8 @@ func TestComposeIssueCommentMessage(t *testing.T) { recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}} msgs, err := composeIssueCommentMessages(&mailCommentContext{ - Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, Content: "test body", Comment: comment, }, "en-US", recipients, false, "issue comment") assert.NoError(t, err) @@ -99,7 +101,8 @@ func TestComposeIssueMessage(t *testing.T) { recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}} msgs, err := composeIssueCommentMessages(&mailCommentContext{ - Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, Content: "test body", }, "en-US", recipients, false, "issue create") assert.NoError(t, err) @@ -145,13 +148,15 @@ func TestTemplateSelection(t *testing.T) { } msg := testComposeIssueCommentMessage(t, &mailCommentContext{ - Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, Content: "test body", }, recipients, false, "TestTemplateSelection") expect(t, msg, "issue/new/subject", "issue/new/body") msg = testComposeIssueCommentMessage(t, &mailCommentContext{ - Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, Content: "test body", Comment: comment, }, recipients, false, "TestTemplateSelection") expect(t, msg, "issue/default/subject", "issue/default/body") @@ -159,13 +164,15 @@ func TestTemplateSelection(t *testing.T) { pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue) comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment) msg = testComposeIssueCommentMessage(t, &mailCommentContext{ - Issue: pull, Doer: doer, ActionType: models.ActionCommentPull, + Context: context.TODO(), // TODO: use a correct context + Issue: pull, Doer: doer, ActionType: models.ActionCommentPull, Content: "test body", Comment: comment, }, recipients, false, "TestTemplateSelection") expect(t, msg, "pull/comment/subject", "pull/comment/body") msg = testComposeIssueCommentMessage(t, &mailCommentContext{ - Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue, Content: "test body", Comment: comment, }, recipients, false, "TestTemplateSelection") expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body") @@ -184,7 +191,8 @@ func TestTemplateServices(t *testing.T) { recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}} msg := testComposeIssueCommentMessage(t, &mailCommentContext{ - Issue: issue, Doer: doer, ActionType: actionType, + Context: context.TODO(), // TODO: use a correct context + Issue: issue, Doer: doer, ActionType: actionType, Content: "test body", Comment: comment, }, recipients, fromMention, "TestTemplateServices") @@ -226,7 +234,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip func TestGenerateAdditionalHeaders(t *testing.T) { doer, _, issue, _ := prepareMailerTest(t) - ctx := &mailCommentContext{Issue: issue, Doer: doer} + ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer} recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"} headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient) |