2019-09-24 10:32:49 +05:30
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2019-09-24 10:32:49 +05:30
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
2024-05-17 20:15:41 +05:30
|
|
|
"context"
|
2019-09-24 10:32:49 +05:30
|
|
|
"testing"
|
|
|
|
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2024-05-17 20:15:41 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/templates"
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
"code.gitea.io/gitea/modules/translation"
|
2023-09-08 10:21:15 +05:30
|
|
|
|
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
2024-05-17 20:15:41 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-09-24 10:32:49 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 07:08:53 +05:30
|
|
|
unittest.MainTest(m)
|
2019-09-24 10:32:49 +05:30
|
|
|
}
|
2024-05-17 20:15:41 +05:30
|
|
|
|
|
|
|
func assertTranslatedLocale(t *testing.T, message string, prefixes ...string) {
|
|
|
|
t.Helper()
|
|
|
|
for _, prefix := range prefixes {
|
|
|
|
assert.NotContains(t, message, prefix, "there is an untranslated locale prefix")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mockMailSettings(send func(msgs ...*Message)) func() {
|
|
|
|
translation.InitLocales(context.Background())
|
|
|
|
subjectTemplates, bodyTemplates = templates.Mailer(context.Background())
|
|
|
|
mailService := setting.Mailer{
|
|
|
|
From: "test@gitea.com",
|
|
|
|
}
|
|
|
|
cleanups := []func(){
|
|
|
|
test.MockVariableValue(&setting.MailService, &mailService),
|
|
|
|
test.MockVariableValue(&setting.Domain, "localhost"),
|
|
|
|
test.MockVariableValue(&SendAsync, send),
|
|
|
|
}
|
|
|
|
return func() {
|
|
|
|
for _, cleanup := range cleanups {
|
|
|
|
cleanup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|