@@ -2,15 +2,14 @@ package sort_test
22
33import (
44 "encoding/json"
5- "sort"
5+ "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
6+ "slices"
67 "testing"
78
89 "github.com/stretchr/testify/assert"
910
1011 "github.com/operator-framework/operator-registry/alpha/declcfg"
1112 "github.com/operator-framework/operator-registry/alpha/property"
12-
13- catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
1413)
1514
1615func TestByVersion (t * testing.T ) {
@@ -56,27 +55,13 @@ func TestByVersion(t *testing.T) {
5655
5756 t .Run ("all bundles valid" , func (t * testing.T ) {
5857 toSort := []declcfg.Bundle {b3 , b2 , b1 }
59- sort .Slice (toSort , func (i , j int ) bool {
60- return catalogsort .ByVersion (& toSort [i ], & toSort [j ]) < 0
61- })
62-
63- assert .Len (t , toSort , 3 )
64- assert .Equal (t , b1 , toSort [0 ])
65- assert .Equal (t , b3 , toSort [1 ])
66- assert .Equal (t , b2 , toSort [2 ])
58+ slices .SortStableFunc (toSort , sort .ByVersion )
59+ assert .Equal (t , []declcfg.Bundle {b1 , b3 , b2 }, toSort )
6760 })
6861
6962 t .Run ("some bundles are missing version" , func (t * testing.T ) {
7063 toSort := []declcfg.Bundle {b3 , b4noVersion , b2 , b5empty , b1 }
71- sort .Slice (toSort , func (i , j int ) bool {
72- return catalogsort .ByVersion (& toSort [i ], & toSort [j ]) < 0
73- })
74-
75- assert .Len (t , toSort , 5 )
76- assert .Equal (t , b1 , toSort [0 ])
77- assert .Equal (t , b3 , toSort [1 ])
78- assert .Equal (t , b2 , toSort [2 ])
79- assert .Equal (t , b4noVersion , toSort [3 ])
80- assert .Equal (t , b5empty , toSort [4 ])
64+ slices .SortStableFunc (toSort , sort .ByVersion )
65+ assert .Equal (t , []declcfg.Bundle {b1 , b3 , b2 , b4noVersion , b5empty }, toSort )
8166 })
8267}
0 commit comments