github.com/kinvolk/docker@v1.13.1/utils/templates/templates_test.go (about) 1 package templates 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestParseStringFunctions(t *testing.T) { 9 tm, err := Parse(`{{join (split . ":") "/"}}`) 10 if err != nil { 11 t.Fatal(err) 12 } 13 14 var b bytes.Buffer 15 if err := tm.Execute(&b, "text:with:colon"); err != nil { 16 t.Fatal(err) 17 } 18 want := "text/with/colon" 19 if b.String() != want { 20 t.Fatalf("expected %s, got %s", want, b.String()) 21 } 22 } 23 24 func TestNewParse(t *testing.T) { 25 tm, err := NewParse("foo", "this is a {{ . }}") 26 if err != nil { 27 t.Fatal(err) 28 } 29 30 var b bytes.Buffer 31 if err := tm.Execute(&b, "string"); err != nil { 32 t.Fatal(err) 33 } 34 want := "this is a string" 35 if b.String() != want { 36 t.Fatalf("expected %s, got %s", want, b.String()) 37 } 38 }