@@ -17,3 +17,69 @@ func TestTemplateWriter(t *testing.T) {
1717 })
1818 })
1919}
20+
21+ func TestTemplateSplitFunction (t * testing.T ) {
22+ Convey ("#RenderTemplate" , t , func () {
23+ templateName := "templateName"
24+ params := map [string ]string {"id" : "app" , "domain" : "example.com" }
25+
26+ templateContent := "{{.id}}{{range Split .domain \" .\" }} {{.}}{{end}}"
27+ Convey ("should split domain as two different strings" , func () {
28+ content , _ := RenderTemplate (templateName , templateContent , params )
29+ So (content , ShouldEqual , "app example com" )
30+ })
31+ })
32+ }
33+
34+ func TestTemplateJoinFunction (t * testing.T ) {
35+ Convey ("#RenderTemplate" , t , func () {
36+ templateName := "templateName"
37+ domains := []string {"example.com" , "example.net" }
38+ params := map [string ][]string {"domains" : domains }
39+
40+ templateContent := "{{Join .domains \" , \" }}"
41+ Convey ("should create a list of two domains separated by comma" , func () {
42+ content , _ := RenderTemplate (templateName , templateContent , params )
43+ So (content , ShouldEqual , "example.com, example.net" )
44+ })
45+ })
46+ }
47+
48+ func TestTemplateReplaceFunction (t * testing.T ) {
49+ Convey ("#RenderTemplate" , t , func () {
50+ templateName := "templateName"
51+ params := map [string ]string {"domain" : "example.com" }
52+
53+ templateContent := "{{Replace .domain \" com\" \" net\" 1}}"
54+ Convey ("should replace example.com into example.net" , func () {
55+ content , _ := RenderTemplate (templateName , templateContent , params )
56+ So (content , ShouldEqual , "example.net" )
57+ })
58+ })
59+ }
60+
61+ func TestTemplateToUpperFunction (t * testing.T ) {
62+ Convey ("#RenderTemplate" , t , func () {
63+ templateName := "templateName"
64+ params := map [string ]string {"id" : "app" , "domain" : "example.com" }
65+
66+ templateContent := "{{.id}} {{ToUpper .domain}}"
67+ Convey ("should transform example.com upper case" , func () {
68+ content , _ := RenderTemplate (templateName , templateContent , params )
69+ So (content , ShouldEqual , "app EXAMPLE.COM" )
70+ })
71+ })
72+ }
73+
74+ func TestTemplateToLowerFunction (t * testing.T ) {
75+ Convey ("#RenderTemplate" , t , func () {
76+ templateName := "templateName"
77+ params := map [string ]string {"domain" : "EXAMPLE.COM" }
78+
79+ templateContent := "{{ToLower .domain}}"
80+ Convey ("should transform example.com lower case" , func () {
81+ content , _ := RenderTemplate (templateName , templateContent , params )
82+ So (content , ShouldEqual , "example.com" )
83+ })
84+ })
85+ }
0 commit comments