2019-09-24 05:02:49 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-09-24 05:02:49 +00:00
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
2024-05-17 14:45:41 +00:00
|
|
|
"context"
|
2019-09-24 05:02:49 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-11-12 14:36:47 +00:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2024-05-17 14:45:41 +00:00
|
|
|
"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 04:51:15 +00:00
|
|
|
|
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
2024-05-17 14:45:41 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-09-24 05:02:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 01:38:53 +00:00
|
|
|
unittest.MainTest(m)
|
2019-09-24 05:02:49 +00:00
|
|
|
}
|
2024-05-17 14:45:41 +00:00
|
|
|
|
2024-07-22 22:17:06 +00:00
|
|
|
func AssertTranslatedLocale(t *testing.T, message string, prefixes ...string) {
|
2024-05-17 14:45:41 +00:00
|
|
|
t.Helper()
|
|
|
|
for _, prefix := range prefixes {
|
|
|
|
assert.NotContains(t, message, prefix, "there is an untranslated locale prefix")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 22:17:06 +00:00
|
|
|
func MockMailSettings(send func(msgs ...*Message)) func() {
|
2024-05-17 14:45:41 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|