Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ help: ## Display this help
## --------------------------------------

.PHONY: test
test: test-tools ## Run the script check-everything.sh which will check all.
test: ## Run the script check-everything.sh which will check all.
TRACE=1 ./hack/check-everything.sh

.PHONY: test-tools
test-tools: ## tests the tools codebase (setup-envtest)
cd tools/setup-envtest && go test ./...

## --------------------------------------
## Binaries
## --------------------------------------
Expand Down
1 change: 1 addition & 0 deletions hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fi

result=0
go test -v -race ${P_FLAG} ${MOD_OPT} ./... --ginkgo.fail-fast ${GINKGO_ARGS} || result=$?
(cd tools/setup-envtest && go test -v -race ${P_FLAG} ${MOD_OPT} ./... --ginkgo.fail-fast ${GINKGO_ARGS}) || result=$?

if [[ -n ${ARTIFACTS:-} ]]; then
mkdir -p ${ARTIFACTS}
Expand Down
2 changes: 1 addition & 1 deletion tools/setup-envtest/remote/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *HTTPClient) ListVersions(ctx context.Context) ([]versions.Set, error) {
}
// sort in inverse order so that the newest one is first
slices.SortStableFunc(res, func(i, j versions.Set) int {
return i.Version.Compare(j.Version)
return j.Version.Compare(i.Version)
})

return res, nil
Expand Down
3 changes: 2 additions & 1 deletion tools/setup-envtest/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (s *Store) List(ctx context.Context, matching Filter) ([]Item, error) {

slices.SortStableFunc(res, func(i, j Item) int {
if !i.Version.Matches(j.Version) {
return i.Version.Compare(j.Version)
// sort in inverse order so that the newest one is first
return j.Version.Compare(i.Version)
}
return orderPlatforms(i.Platform, j.Platform)
})
Expand Down
20 changes: 20 additions & 0 deletions tools/setup-envtest/versions/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package versions_test

import (
"math/rand/v2"
"slices"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -44,6 +47,23 @@ var _ = Describe("Concrete", func() {
Specify("newer major should be newer", func() {
Expect(ver1163.Compare(Concrete{Major: 0, Minor: 16, Patch: 3})).To(Equal(1))
})

Describe("sorting", func() {
ver16 := Concrete{Major: 1, Minor: 16}
ver17 := Concrete{Major: 1, Minor: 17}
many := []Concrete{ver16, ver17, ver1163}

BeforeEach(func() {
rand.Shuffle(len(many), func(i, j int) {
many[i], many[j] = many[j], many[i]
})
})

Specify("newer versions are later", func() {
slices.SortStableFunc(many, Concrete.Compare)
Expect(many).To(Equal([]Concrete{ver16, ver1163, ver17}))
})
})
})
})

Expand Down
Loading