forked from Tinkoff/prometheus-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
41 lines (37 loc) · 1.06 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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateTemplate(t *testing.T) {
data := map[string]interface{}{
"arr": []string{
"1",
"2",
"3",
},
}
tests := map[string]string{
`{{ "abcdef" | replace "abc" }}`: "def",
`{{ "" | default "abc" }}`: "abc",
`{{ true | default "foobar" }}`: "true",
`{{ "foobar" | default true }}`: "foobar",
`{{ default "abc" 0 }}`: "0",
`{{ length "abc" }}`: "3",
`{{ length .arr }}`: "3",
`{{ length 123 }}`: "0",
`{{ lower "ABC" }}`: "abc",
`{{ upper "abc" }}`: "ABC",
`{{ urlencode "?abcd=1&efg=2" }}`: "%3Fabcd%3D1%26efg%3D2",
`{{ trim " abc " }}`: "abc",
`{{ yesno "yes" "no" true }}`: "yes",
`{{ yesno "yes" "no" false }}`: "no",
}
for in, out := range tests {
result, err := GenerateTemplate(in, "test", data)
assert.NoError(t, err)
assert.Equal(t, out, result)
}
_, err := GenerateTemplate("{{nil}}", "test", nil)
assert.Error(t, err)
}