github.com/kubeshop/testkube@v1.17.23/pkg/utils/text/tostr_test.go (about) 1 package text 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 type stringerTestImpl struct { 10 name string 11 } 12 13 func (tt stringerTestImpl) String() string { 14 return tt.name 15 } 16 17 func TestToStr(t *testing.T) { 18 19 t.Run("converts stringer to string", func(t *testing.T) { 20 test := stringerTestImpl{name: "test"} 21 assert.Equal(t, "test", ToStr(test)) 22 }) 23 24 t.Run("converts int to str", func(t *testing.T) { 25 test := 1 26 assert.Equal(t, "1", ToStr(test)) 27 }) 28 29 t.Run("converts float to str", func(t *testing.T) { 30 test := 1.1 31 assert.Equal(t, "1.1", ToStr(test)) 32 }) 33 34 t.Run("converts bool to str", func(t *testing.T) { 35 test := true 36 assert.Equal(t, "true", ToStr(test)) 37 }) 38 39 t.Run("converts nil to str", func(t *testing.T) { 40 var test *string 41 assert.Equal(t, "<nil>", ToStr(test)) 42 }) 43 44 }