Skip to content

Commit a6adaac

Browse files
authored
Merge pull request #3380 from cbandy/envtest-sorting
🐛 setup-envtest: select the newest Kubernetes by default
2 parents 887f011 + 528ec24 commit a6adaac

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ help: ## Display this help
6969
## --------------------------------------
7070

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

75-
.PHONY: test-tools
76-
test-tools: ## tests the tools codebase (setup-envtest)
77-
cd tools/setup-envtest && go test ./...
78-
7975
## --------------------------------------
8076
## Binaries
8177
## --------------------------------------

hack/test-all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fi
2626

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

3031
if [[ -n ${ARTIFACTS:-} ]]; then
3132
mkdir -p ${ARTIFACTS}

tools/setup-envtest/remote/http_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (c *HTTPClient) ListVersions(ctx context.Context) ([]versions.Set, error) {
8888
}
8989
// sort in inverse order so that the newest one is first
9090
slices.SortStableFunc(res, func(i, j versions.Set) int {
91-
return i.Version.Compare(j.Version)
91+
return j.Version.Compare(i.Version)
9292
})
9393

9494
return res, nil

tools/setup-envtest/store/store.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (s *Store) List(ctx context.Context, matching Filter) ([]Item, error) {
105105

106106
slices.SortStableFunc(res, func(i, j Item) int {
107107
if !i.Version.Matches(j.Version) {
108-
return i.Version.Compare(j.Version)
108+
// sort in inverse order so that the newest one is first
109+
return j.Version.Compare(i.Version)
109110
}
110111
return orderPlatforms(i.Platform, j.Platform)
111112
})

tools/setup-envtest/versions/misc_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package versions_test
1818

1919
import (
20+
"math/rand/v2"
21+
"slices"
22+
2023
. "github.com/onsi/ginkgo/v2"
2124
. "github.com/onsi/gomega"
2225

@@ -44,6 +47,23 @@ var _ = Describe("Concrete", func() {
4447
Specify("newer major should be newer", func() {
4548
Expect(ver1163.Compare(Concrete{Major: 0, Minor: 16, Patch: 3})).To(Equal(1))
4649
})
50+
51+
Describe("sorting", func() {
52+
ver16 := Concrete{Major: 1, Minor: 16}
53+
ver17 := Concrete{Major: 1, Minor: 17}
54+
many := []Concrete{ver16, ver17, ver1163}
55+
56+
BeforeEach(func() {
57+
rand.Shuffle(len(many), func(i, j int) {
58+
many[i], many[j] = many[j], many[i]
59+
})
60+
})
61+
62+
Specify("newer versions are later", func() {
63+
slices.SortStableFunc(many, Concrete.Compare)
64+
Expect(many).To(Equal([]Concrete{ver16, ver1163, ver17}))
65+
})
66+
})
4767
})
4868
})
4969

0 commit comments

Comments
 (0)