From e6568899b70e4c6cf30b7da853013c45e9a9406e Mon Sep 17 00:00:00 2001 From: Zach Burgess Date: Thu, 10 Jul 2025 12:58:03 -0700 Subject: [PATCH] Improve test coverage for `defaults.go` --- defaults_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/defaults_test.go b/defaults_test.go index a35ebf62..c9da32d8 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}}`