From 25be1d4391f7745834f6185b71cf84efd06ae069 Mon Sep 17 00:00:00 2001 From: Zach Burgess Date: Thu, 10 Jul 2025 13:47:09 -0700 Subject: [PATCH 1/3] Improve test coverage for `strval` function --- strings_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/strings_test.go b/strings_test.go index a75ab086..be9cf654 100644 --- a/strings_test.go +++ b/strings_test.go @@ -3,6 +3,7 @@ package sprig import ( "encoding/base32" "encoding/base64" + "errors" "fmt" "testing" "unicode/utf8" @@ -121,8 +122,15 @@ func TestSplitn(t *testing.T) { } func TestToString(t *testing.T) { - tpl := `{{ toString 1 | kindOf }}` - assert.NoError(t, runt(tpl, "string")) + tests := []interface{}{ + "string", + []byte("bytes"), + errors.New("error"), + } + for _, test := range tests { + tpl := `{{ toString .Value| kindOf }}` + assert.NoError(t, runtv(tpl, "string", map[string]interface{}{"Value": test})) + } } func TestToStrings(t *testing.T) { From c4871efc5aee265e2b990ba0019d9182ea1d1ef7 Mon Sep 17 00:00:00 2001 From: Zach Burgess Date: Thu, 10 Jul 2025 13:47:09 -0700 Subject: [PATCH 2/3] Improve test coverage for `strval` function --- strings_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/strings_test.go b/strings_test.go index be9cf654..6f27a175 100644 --- a/strings_test.go +++ b/strings_test.go @@ -123,6 +123,7 @@ func TestSplitn(t *testing.T) { func TestToString(t *testing.T) { tests := []interface{}{ + 1, "string", []byte("bytes"), errors.New("error"), From 6b97368d43398e4f9117b9a9bca37f03ccc8ea62 Mon Sep 17 00:00:00 2001 From: Zach Burgess Date: Mon, 14 Jul 2025 11:59:24 -0700 Subject: [PATCH 3/3] Add test case for `fmt.Stringer` case of `strval` function. --- strings_test.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/strings_test.go b/strings_test.go index 6f27a175..28b9a1e8 100644 --- a/strings_test.go +++ b/strings_test.go @@ -11,6 +11,15 @@ import ( "github.com/stretchr/testify/assert" ) +type stringerImpl struct { + Value string +} + +// String satisfies the Stringer interface. +func (s stringerImpl) String() string { + return s.Value +} + func TestSubstr(t *testing.T) { tpl := `{{"fooo" | substr 0 3 }}` if err := runt(tpl, "foo"); err != nil { @@ -127,9 +136,12 @@ func TestToString(t *testing.T) { "string", []byte("bytes"), errors.New("error"), + stringerImpl{ + Value: "stringer", + }, } for _, test := range tests { - tpl := `{{ toString .Value| kindOf }}` + tpl := `{{ toString .Value | kindOf }}` assert.NoError(t, runtv(tpl, "string", map[string]interface{}{"Value": test})) } }