forked from hairyhenderson/gomplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
template_test.go
60 lines (52 loc) · 1.19 KB
/
template_test.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gomplate
import (
"testing"
_ "github.com/flanksource/gomplate/v3/js"
_ "github.com/robertkrimen/otto/underscore"
)
func TestCacheKeyConsistency(t *testing.T) {
var hello = func() any {
return "world"
}
var foo = func() any {
return "bar"
}
{
tt := Template{
Expression: "{{.name}}{{.age}}",
Functions: map[string]any{
"hello": hello,
"Hello": foo,
"foo": foo,
"Foo": foo,
},
}
expectedCacheKey := tt.CacheKey(map[string]any{"age": 19, "name": "james"})
for i := 0; i < 10; i++ {
key := tt.CacheKey(map[string]any{"age": 19, "name": "james"})
if key != expectedCacheKey {
t.Errorf("cache key mismatch: %s != %s", key, expectedCacheKey)
}
}
}
{
tt := Template{
Template: "{{.name}}{{.age}}",
LeftDelim: "{{",
RightDelim: "}}",
Functions: map[string]any{
"hello": hello,
"Hello": foo,
"foo": foo,
"Foo": foo,
},
}
expectCacheKey := tt.CacheKey(map[string]any{"age": 19, "name": "james"})
for i := 0; i < 10; i++ {
key := tt.CacheKey(map[string]any{"age": 19, "name": "james"})
if key != expectCacheKey {
t.Errorf("cache key mismatch: %s != %s", key, expectCacheKey)
}
}
}
}