Skip to content

Commit

Permalink
Finish the tests for list
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasaschan committed Jun 12, 2024
1 parent b696321 commit 989e7fb
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/envtest/setup/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,53 @@ var _ = Describe("List", func() {

Expect(result).To(HaveExactElements(expected))
})

It("should skip non-matching local contents", func() {
spec := versions.Spec{
Selector: versions.PatchSelector{Major: 1, Minor: 16, Patch: versions.AnyPoint},
}
result, err := list.List(
ctx,
spec,
list.NoDownload(true),
list.WithPlatform("linux", "*"),
list.WithEnvOptions(envOpts...),
)
Expect(err).NotTo(HaveOccurred())

expected := make([]list.Result, 0)
for _, v := range testhelpers.LocalVersions {
if !spec.Matches(v.Version) {
continue
}
for _, p := range v.Platforms {
if p.OS != "linux" {
continue
}

expected = append(expected, list.Result{
Version: v.Version,
Platform: p.Platform,
Status: list.Installed,
})
}
}
// this sorting ensures the List method fulfils the contract of
// returning the most relevant items first
slices.SortFunc(expected, func(a, b list.Result) int {
return cmp.Or(
// we want the results sorted in descending order by version
cmp.Compare(b.Version.Major, a.Version.Major),
cmp.Compare(b.Version.Minor, a.Version.Minor),
cmp.Compare(b.Version.Patch, a.Version.Patch),
// ..and then in ascending order by platform
cmp.Compare(a.Platform.OS, b.Platform.OS),
cmp.Compare(a.Platform.Arch, b.Platform.Arch),
)
})

Expect(result).To(HaveExactElements(expected))
})
})

Context("when downloads are enabled", func() {
Expand Down

0 comments on commit 989e7fb

Please sign in to comment.