mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 13:25:36 +03:00
test(services/mailer): Add option for mailer to override mail headers
Use MockVariableValue to avoid undesirable side effects between tests modifying global variables. TestToMessage relies on *setting.MailService being set, which will not be the case if run individually with test-sqlite#TestToMessage and fail.
This commit is contained in:
parent
1d4bff4f65
commit
21b94765ce
1 changed files with 9 additions and 11 deletions
|
@ -10,17 +10,16 @@ import (
|
||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateMessageID(t *testing.T) {
|
func TestGenerateMessageID(t *testing.T) {
|
||||||
mailService := setting.Mailer{
|
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{
|
||||||
From: "test@gitea.com",
|
From: "test@gitea.com",
|
||||||
}
|
})()
|
||||||
|
defer test.MockVariableValue(&setting.Domain, "localhost")()
|
||||||
setting.MailService = &mailService
|
|
||||||
setting.Domain = "localhost"
|
|
||||||
|
|
||||||
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
||||||
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
||||||
|
@ -40,7 +39,7 @@ func TestGenerateMessageID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateMessageIDForRelease(t *testing.T) {
|
func TestGenerateMessageIDForRelease(t *testing.T) {
|
||||||
setting.Domain = "localhost"
|
defer test.MockVariableValue(&setting.Domain, "localhost")()
|
||||||
|
|
||||||
rel := repo_model.Release{
|
rel := repo_model.Release{
|
||||||
ID: 42,
|
ID: 42,
|
||||||
|
@ -54,11 +53,10 @@ func TestGenerateMessageIDForRelease(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToMessage(t *testing.T) {
|
func TestToMessage(t *testing.T) {
|
||||||
oldConf := *setting.MailService
|
defer test.MockVariableValue(&setting.MailService, &setting.Mailer{
|
||||||
defer func() {
|
From: "test@gitea.com",
|
||||||
setting.MailService = &oldConf
|
})()
|
||||||
}()
|
defer test.MockVariableValue(&setting.Domain, "localhost")()
|
||||||
setting.MailService.From = "test@gitea.com"
|
|
||||||
|
|
||||||
m1 := Message{
|
m1 := Message{
|
||||||
Info: "info",
|
Info: "info",
|
||||||
|
|
Loading…
Reference in a new issue