-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
79 lines (60 loc) · 1.29 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"os"
"testing"
"time"
)
/*
* Data models to hold test cases for various checks
*/
type TestTemplateTestCase struct {
text string
match bool
}
type TestTemplateCmdCase struct {
text string
expect string
}
/*
* Tests for primary functions
*/
func Test_templateTest(t *testing.T) {
cases := []TestTemplateTestCase{
{"{{ isotime 2006/01/02 }}", true},
{"wibble {{ isotime 2006/01/02 }} and wobble", true},
{"{{ env HOME }}", true},
{"{{env HOME}}", true},
{"{{ isotime 2006/01/02/15 ", false},
{"{{ isotime 2006/01/02/15 }", false},
{"}}", false},
}
for _, c := range cases {
// Look for template command
match := templateTest(c.text)
expect(t, c.match, match)
}
}
func Test_templateCmd(t *testing.T) {
time := time.Now()
format := "2006/01/02"
envKey := "CHECKJSONENV"
envVal := "not_hazardous"
err := os.Setenv(envKey, envVal)
check(err)
cases := []TestTemplateCmdCase{
{fmt.Sprintf("isotime %s", format),
fmt.Sprintf("%s", time.Format(format))},
{fmt.Sprintf("env %s }}", envKey),
fmt.Sprintf("%s", envVal)},
{"noppy nop",
"noppy nop"},
}
for _, c := range cases {
// Do substitutions of template commands
result := templateCmd(c.text)
expect(t, c.expect, result)
}
err = os.Setenv(envKey, "")
check(err)
}