2019-09-24 08:02:49 +03:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-09-24 08:02:49 +03:00
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
2024-05-17 17:45:41 +03:00
|
|
|
"context"
|
2019-09-24 08:02:49 +03:00
|
|
|
"testing"
|
|
|
|
|
2021-11-12 17:36:47 +03:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2024-05-17 17:45:41 +03: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 07:51:15 +03:00
|
|
|
|
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
2024-05-17 17:45:41 +03:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-09-24 08:02:49 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 04:38:53 +03:00
|
|
|
unittest.MainTest(m)
|
2019-09-24 08:02:49 +03:00
|
|
|
}
|
2024-05-17 17:45:41 +03:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|