mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-02-03 20:51:07 -05:00
- Create `modules/testimport/import.go` to centralize blank import needed for tests (in order to run the `init` function) to simplify maintenance. - Remove the imports that are not needed. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10662 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: limiting-factor <limiting-factor@posteo.com> Co-committed-by: limiting-factor <limiting-factor@posteo.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package mailer
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"forgejo.org/models/db"
|
|
org_model "forgejo.org/models/organization"
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/templates"
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/modules/translation"
|
|
|
|
_ "forgejo.org/modules/testimport"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
unittest.MainTest(m)
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
|
|
func CleanUpUsers(ctx context.Context, users []*user_model.User) {
|
|
for _, u := range users {
|
|
if u.IsOrganization() {
|
|
org_model.DeleteOrganization(ctx, (*org_model.Organization)(u))
|
|
} else {
|
|
db.DeleteByID[user_model.User](ctx, u.ID)
|
|
db.DeleteByBean(ctx, &user_model.EmailAddress{UID: u.ID})
|
|
}
|
|
}
|
|
}
|