1
0
mirror of https://github.com/docker/cli.git synced 2026-01-26 15:41:42 +03:00
Files
cli/components/engine/utils/templates/templates_test.go
David Calavera a66058a138 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>
Upstream-commit: 8514880997bd1bc944769dcc41e52307bb01f7ff
Component: engine
2016-03-09 19:37:12 -05:00

39 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())
}
}