diff options
Diffstat (limited to 'pkg/utils/utils_test.go')
-rw-r--r-- | pkg/utils/utils_test.go | 158 |
1 files changed, 0 insertions, 158 deletions
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index 7cf8e958b..82df3e94a 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -196,166 +196,8 @@ func TestDisplayArraysAligned(t *testing.T) { } } -type myDisplayable struct { - strings []string -} - type myStruct struct{} -// GetDisplayStrings is a function. -func (d *myDisplayable) GetDisplayStrings(isFocused bool) []string { - if isFocused { - return append(d.strings, "blah") - } - return d.strings -} - -// TestGetDisplayStringArrays is a function. -func TestGetDisplayStringArrays(t *testing.T) { - type scenario struct { - input []Displayable - isFocused bool - expected [][]string - } - - scenarios := []scenario{ - { - []Displayable{ - Displayable(&myDisplayable{[]string{"a", "b"}}), - Displayable(&myDisplayable{[]string{"c", "d"}}), - }, - false, - [][]string{{"a", "b"}, {"c", "d"}}, - }, - { - []Displayable{ - Displayable(&myDisplayable{[]string{"a", "b"}}), - Displayable(&myDisplayable{[]string{"c", "d"}}), - }, - true, - [][]string{{"a", "b", "blah"}, {"c", "d", "blah"}}, - }, - } - - for _, s := range scenarios { - assert.EqualValues(t, s.expected, getDisplayStringArrays(s.input, s.isFocused)) - } -} - -// TestRenderDisplayableList is a function. -func TestRenderDisplayableList(t *testing.T) { - type scenario struct { - input []Displayable - isFocused bool - expectedString string - expectedErrorMessage string - } - - scenarios := []scenario{ - { - []Displayable{ - Displayable(&myDisplayable{[]string{}}), - Displayable(&myDisplayable{[]string{}}), - }, - false, - "\n", - "", - }, - { - []Displayable{ - Displayable(&myDisplayable{[]string{"aa", "b"}}), - Displayable(&myDisplayable{[]string{"c", "d"}}), - }, - false, - "aa b\nc d", - "", - }, - { - []Displayable{ - Displayable(&myDisplayable{[]string{"a"}}), - Displayable(&myDisplayable{[]string{"b", "c"}}), - }, - false, - "a \nb c", - "", - }, - { - []Displayable{ - Displayable(&myDisplayable{[]string{"a"}}), - Displayable(&myDisplayable{[]string{"b"}}), - }, - true, - "a blah\nb blah", - "", - }, - } - - for _, s := range scenarios { - str, err := renderDisplayableList(s.input, s.isFocused) - assert.EqualValues(t, s.expectedString, str) - if s.expectedErrorMessage != "" { - assert.EqualError(t, err, s.expectedErrorMessage) - } else { - assert.NoError(t, err) - } - } -} - -// TestRenderList is a function. -func TestRenderList(t *testing.T) { - type scenario struct { - input interface{} - isFocused bool - expectedString string - expectedErrorMessage string - } - - scenarios := []scenario{ - { - []*myDisplayable{ - {[]string{"aa", "b"}}, - {[]string{"c", "d"}}, - }, - false, - "aa b\nc d", - "", - }, - { - []*myStruct{ - {}, - {}, - }, - false, - "", - "item does not implement the Displayable interface", - }, - { - &myStruct{}, - false, - "", - "RenderList given a non-slice type", - }, - { - []*myDisplayable{ - {[]string{"a"}}, - }, - true, - "a blah", - "", - }, - } - - for _, s := range scenarios { - str, err := RenderList(s.input, s.isFocused) - assert.EqualValues(t, s.expectedString, str) - if s.expectedErrorMessage != "" { - assert.EqualError(t, err, s.expectedErrorMessage) - } else { - assert.NoError(t, err) - } - } -} - // TestGetPaddedDisplayStrings is a function. func TestGetPaddedDisplayStrings(t *testing.T) { type scenario struct { |