get.porter.sh/porter@v1.3.0/pkg/storage/output_test.go (about) 1 package storage 2 3 import ( 4 "sort" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestOutputs_Sort(t *testing.T) { 12 o := NewOutputs([]Output{ 13 {Name: "a"}, 14 {Name: "c"}, 15 {Name: "b"}, 16 }) 17 18 sort.Sort(o) 19 20 wantNames := []string{"a", "b", "c"} 21 gotNames := make([]string, 0, 3) 22 for i := 0; i < o.Len(); i++ { 23 output, ok := o.GetByIndex(i) 24 require.True(t, ok, "GetByIndex failed") 25 gotNames = append(gotNames, output.Name) 26 } 27 28 assert.Equal(t, wantNames, gotNames) 29 }