Skip to content

Commit 03cf411

Browse files
committed
Add unit test for getting templates concurrently
1 parent ff6580b commit 03cf411

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

templator_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,35 @@ func TestNewRegistry(t *testing.T) {
8383
}
8484
}
8585

86+
func TestRegistry_Get(t *testing.T) {
87+
t.Parallel()
88+
89+
t.Run("can get templates concurrently", func(t *testing.T) {
90+
fs := fstest.MapFS{
91+
"custom/template1.html": &fstest.MapFile{
92+
Data: []byte(testHTMLTemplate),
93+
},
94+
}
95+
96+
opts := []Option[TestData]{WithTemplatesPath[TestData]("custom")}
97+
98+
registry, err := NewRegistry(fs, opts...)
99+
require.NoError(t, err)
100+
101+
var wg sync.WaitGroup
102+
103+
wg.Add(2)
104+
for i := 0; i < 2; i++ {
105+
go func(wg *sync.WaitGroup) {
106+
defer wg.Done()
107+
_, err := registry.Get("template1")
108+
require.NoError(t, err)
109+
}(&wg)
110+
}
111+
wg.Wait()
112+
})
113+
}
114+
86115
func TestHandler(t *testing.T) {
87116
t.Parallel()
88117

@@ -342,7 +371,7 @@ func TestRegistry_Options(t *testing.T) {
342371
}
343372
}
344373

345-
func TestWithFuncs(t *testing.T) {
374+
func TestWithTemplateFuncs(t *testing.T) {
346375
t.Parallel()
347376

348377
funcMap := template.FuncMap{

0 commit comments

Comments
 (0)