diff --git a/defaults_test.go b/defaults_test.go index a35ebf6..c9da32d 100644 --- a/defaults_test.go +++ b/defaults_test.go @@ -1,6 +1,7 @@ package sprig import ( + "math" "testing" "github.com/stretchr/testify/assert" @@ -150,6 +151,15 @@ func TestToJson(t *testing.T) { } } +func TestMustToJson(t *testing.T) { + dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": math.NaN()}} + + tpl := `{{.Top | mustToJson}}` + if err := runtv(tpl, "", dict); err == nil { + t.Error("expected err, got nil") + } +} + func TestToPrettyJson(t *testing.T) { dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42}} tpl := `{{.Top | toPrettyJson}}` @@ -163,6 +173,15 @@ func TestToPrettyJson(t *testing.T) { } } +func TestMustToPrettyJson(t *testing.T) { + dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": math.NaN()}} + + tpl := `{{.Top | mustToPrettyJson}}` + if err := runtv(tpl, "", dict); err == nil { + t.Error("expected err, got nil") + } +} + func TestToRawJson(t *testing.T) { dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42, "html": ""}} tpl := `{{.Top | toRawJson}}`