Skip to content

Commit b7d00a1

Browse files
committed
test(mail): assert the base partials stay compiled
The "base/" partials are excluded from MailRender.TemplateNames but must remain in the compiled template set, otherwise every mail that includes them fails to render. Guard the invariant with a test instead of a comment. Assisted-by: Claude:Opus 4.8
1 parent 9050f0a commit b7d00a1

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

modules/templates/mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func newMailRenderer() (*MailRender, error) {
130130
renderer.TemplateNames = slices.DeleteFunc(slices.Clone(names), func(name string) bool {
131131
return strings.HasPrefix(name, "base/")
132132
})
133-
return names, nil // the "base/" partials must stay compiled
133+
return names, nil
134134
},
135135
readTemplateContent: func(name string) ([]byte, error) {
136136
content, err := assetFS.ReadFile("mail/" + name + ".tmpl")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2026 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package mailer
5+
6+
import (
7+
"strings"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestMailTemplatesBasePartials(t *testing.T) {
14+
for _, name := range LoadedTemplates().TemplateNames {
15+
assert.False(t, strings.HasPrefix(name, "base/"), "partial %q must not be listed as a mail", name)
16+
}
17+
for _, name := range []string{"base/head", "base/footer", "base/footer_copyright"} {
18+
assert.True(t, LoadedTemplates().BodyTemplates.HasTemplate(name), "partial %q must stay compiled", name)
19+
}
20+
}

0 commit comments

Comments
 (0)