1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/utils/templates/templates_test.go
David Calavera 8514880997 Provide basic string manupilation functions for template executions.
This change centralizes the template manipulation in a single package
and adds basic string functions to their execution.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2016-03-09 19:37:12 -05:00

38 lines
705 B
Go

package templates
import (
"bytes"
"testing"
)
func TestParseStringFunctions(t *testing.T) {
tm, err := Parse(`{{join (split . ":") "/"}}`)
if err != nil {
t.Fatal(err)
}
var b bytes.Buffer
if err := tm.Execute(&b, "text:with:colon"); err != nil {
t.Fatal(err)
}
want := "text/with/colon"
if b.String() != want {
t.Fatalf("expected %s, got %s", want, b.String())
}
}
func TestNewParse(t *testing.T) {
tm, err := NewParse("foo", "this is a {{ . }}")
if err != nil {
t.Fatal(err)
}
var b bytes.Buffer
if err := tm.Execute(&b, "string"); err != nil {
t.Fatal(err)
}
want := "this is a string"
if b.String() != want {
t.Fatalf("expected %s, got %s", want, b.String())
}
}