|
|
|
@ -45,17 +45,6 @@ func testString(t *testing.T, template string, context interface{}, expected str
|
|
|
|
|
assert.Equal(t, actual, expected)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testStringMatch(t *testing.T, template string, context interface{}, pattern string) {
|
|
|
|
|
sut := testLoader(LoaderOpts{})
|
|
|
|
|
|
|
|
|
|
templ, err := sut.LoadTemplate(template)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
actual, err := templ.Render(context)
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.Regexp(t, actual, pattern)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testFile(t *testing.T, name string, context interface{}, expected string) {
|
|
|
|
|
sut := testLoader(LoaderOpts{})
|
|
|
|
|
|
|
|
|
@ -249,12 +238,13 @@ func TestDateHelper(t *testing.T) {
|
|
|
|
|
testString(t, "{{date now 'timestamp'}}", context, "200911172034")
|
|
|
|
|
testString(t, "{{date now 'timestamp-unix'}}", context, "1258490098")
|
|
|
|
|
testString(t, "{{date now 'cust: %Y-%m'}}", context, "cust: 2009-11")
|
|
|
|
|
testStringMatch(t, "{{date now 'elapsed'}}", context, `[\d]+ years ago`)
|
|
|
|
|
testString(t, "{{date now 'elapsed'}}", context, "14 years ago")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetDateHelper(t *testing.T) {
|
|
|
|
|
context := map[string]interface{}{"now": time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC)}
|
|
|
|
|
testStringMatch(t, "{{get-date \"2009-11-17T20:34:58\"}}", context, `2009-11-17 20:34:58 \+[\d]{4} [A-Z]+`)
|
|
|
|
|
localOffsetAndTZ := time.Now().Format("-0700 MST")
|
|
|
|
|
testString(t, "{{get-date \"2009-11-17T20:34:58\"}}", context, "2009-11-17 20:34:58 "+localOffsetAndTZ)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestShellHelper(t *testing.T) {
|
|
|
|
|