@@ -2,15 +2,14 @@ package sort_test
2
2
3
3
import (
4
4
"encoding/json"
5
- "sort"
5
+ "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
6
+ "slices"
6
7
"testing"
7
8
8
9
"github.com/stretchr/testify/assert"
9
10
10
11
"github.com/operator-framework/operator-registry/alpha/declcfg"
11
12
"github.com/operator-framework/operator-registry/alpha/property"
12
-
13
- catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
14
13
)
15
14
16
15
func TestByVersion (t * testing.T ) {
@@ -56,27 +55,13 @@ func TestByVersion(t *testing.T) {
56
55
57
56
t .Run ("all bundles valid" , func (t * testing.T ) {
58
57
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 )
67
60
})
68
61
69
62
t .Run ("some bundles are missing version" , func (t * testing.T ) {
70
63
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 )
81
66
})
82
67
}
0 commit comments