diff options
Diffstat (limited to 'services/mailer/mail_test.go')
-rw-r--r-- | services/mailer/mail_test.go | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go index 6a175337ad..07690063cd 100644 --- a/services/mailer/mail_test.go +++ b/services/mailer/mail_test.go @@ -44,7 +44,7 @@ const bodyTpl = ` func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) { assert.NoError(t, unittest.PrepareTestDatabase()) - var mailService = setting.Mailer{ + mailService := setting.Mailer{ From: "test@gitea.com", } @@ -67,8 +67,10 @@ func TestComposeIssueCommentMessage(t *testing.T) { InitMailRender(stpl, btpl) 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, - Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment") + msgs, err := composeIssueCommentMessages(&mailCommentContext{ + Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, + Content: "test body", Comment: comment, + }, "en-US", recipients, false, "issue comment") assert.NoError(t, err) assert.Len(t, msgs, 2) gomailMsg := msgs[0].ToMessage() @@ -94,8 +96,10 @@ func TestComposeIssueMessage(t *testing.T) { InitMailRender(stpl, btpl) 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, - Content: "test body"}, "en-US", recipients, false, "issue create") + msgs, err := composeIssueCommentMessages(&mailCommentContext{ + Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, + Content: "test body", + }, "en-US", recipients, false, "issue create") assert.NoError(t, err) assert.Len(t, msgs, 2) @@ -138,22 +142,30 @@ func TestTemplateSelection(t *testing.T) { assert.Contains(t, wholemsg, expBody) } - msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue, - Content: "test body"}, recipients, false, "TestTemplateSelection") + msg := testComposeIssueCommentMessage(t, &mailCommentContext{ + 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, - Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection") + msg = testComposeIssueCommentMessage(t, &mailCommentContext{ + Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue, + Content: "test body", Comment: comment, + }, recipients, false, "TestTemplateSelection") expect(t, msg, "issue/default/subject", "issue/default/body") 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, - Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection") + msg = testComposeIssueCommentMessage(t, &mailCommentContext{ + 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, - Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection") + msg = testComposeIssueCommentMessage(t, &mailCommentContext{ + 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") } @@ -162,15 +174,17 @@ func TestTemplateServices(t *testing.T) { assert.NoError(t, issue.LoadRepo()) expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User, - actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) { - + actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string, + ) { stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject)) btpl := template.Must(template.New("issue/default").Parse(tplBody)) InitMailRender(stpl, btpl) recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}} - msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType, - Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices") + msg := testComposeIssueCommentMessage(t, &mailCommentContext{ + Issue: issue, Doer: doer, ActionType: actionType, + Content: "test body", Comment: comment, + }, recipients, fromMention, "TestTemplateServices") subject := msg.ToMessage().GetHeader("Subject") msgbuf := new(bytes.Buffer) |