Skip to content

Commit 006ceb1

Browse files
authored
Merge pull request #448 from zachburg/strings_test_coverage
Improve test coverage for `strval` function
2 parents 007421e + 6b97368 commit 006ceb1

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

strings_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ package sprig
33
import (
44
"encoding/base32"
55
"encoding/base64"
6+
"errors"
67
"fmt"
78
"testing"
89
"unicode/utf8"
910

1011
"github.com/stretchr/testify/assert"
1112
)
1213

14+
type stringerImpl struct {
15+
Value string
16+
}
17+
18+
// String satisfies the Stringer interface.
19+
func (s stringerImpl) String() string {
20+
return s.Value
21+
}
22+
1323
func TestSubstr(t *testing.T) {
1424
tpl := `{{"fooo" | substr 0 3 }}`
1525
if err := runt(tpl, "foo"); err != nil {
@@ -121,8 +131,19 @@ func TestSplitn(t *testing.T) {
121131
}
122132

123133
func TestToString(t *testing.T) {
124-
tpl := `{{ toString 1 | kindOf }}`
125-
assert.NoError(t, runt(tpl, "string"))
134+
tests := []interface{}{
135+
1,
136+
"string",
137+
[]byte("bytes"),
138+
errors.New("error"),
139+
stringerImpl{
140+
Value: "stringer",
141+
},
142+
}
143+
for _, test := range tests {
144+
tpl := `{{ toString .Value | kindOf }}`
145+
assert.NoError(t, runtv(tpl, "string", map[string]interface{}{"Value": test}))
146+
}
126147
}
127148

128149
func TestToStrings(t *testing.T) {

0 commit comments

Comments
 (0)