-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_embedded_func_override_test.go
More file actions
44 lines (36 loc) · 1.1 KB
/
data_embedded_func_override_test.go
File metadata and controls
44 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//go:build !live
// +build !live
package gobookmarks
import (
"bytes"
"strings"
"testing"
)
func TestGetCompiledTemplates_FuncOverride(t *testing.T) {
// Define a custom FuncMap with a specific override
// We use the existing mock-like func map from data_test.go which is already
// populated with safe dummy functions for testing.
safeFuncs := testFuncMap()
// And the specific override we want to test
safeFuncs["version"] = func() string {
return "OVERRIDDEN_VERSION"
}
// Get the compiled templates with the override applied
tmpl := GetCompiledTemplates(safeFuncs)
// Execute a template that uses {{ version }}
// "loginPage.gohtml" typically uses {{ version }} in the footer
var buf bytes.Buffer
data := struct {
*CoreData
Error string
}{
CoreData: &CoreData{Title: "Test", UserRef: "user"},
}
if err := tmpl.ExecuteTemplate(&buf, "loginPage.gohtml", data); err != nil {
t.Fatalf("failed to execute template: %v", err)
}
output := buf.String()
if !strings.Contains(output, "OVERRIDDEN_VERSION") {
t.Errorf("expected output to contain 'OVERRIDDEN_VERSION', but got:\n%s", output)
}
}