@@ -97,6 +97,53 @@ var _ = Describe("List", func() {
97
97
98
98
Expect (result ).To (HaveExactElements (expected ))
99
99
})
100
+
101
+ It ("should skip non-matching local contents" , func () {
102
+ spec := versions.Spec {
103
+ Selector : versions.PatchSelector {Major : 1 , Minor : 16 , Patch : versions .AnyPoint },
104
+ }
105
+ result , err := list .List (
106
+ ctx ,
107
+ spec ,
108
+ list .NoDownload (true ),
109
+ list .WithPlatform ("linux" , "*" ),
110
+ list .WithEnvOptions (envOpts ... ),
111
+ )
112
+ Expect (err ).NotTo (HaveOccurred ())
113
+
114
+ expected := make ([]list.Result , 0 )
115
+ for _ , v := range testhelpers .LocalVersions {
116
+ if ! spec .Matches (v .Version ) {
117
+ continue
118
+ }
119
+ for _ , p := range v .Platforms {
120
+ if p .OS != "linux" {
121
+ continue
122
+ }
123
+
124
+ expected = append (expected , list.Result {
125
+ Version : v .Version ,
126
+ Platform : p .Platform ,
127
+ Status : list .Installed ,
128
+ })
129
+ }
130
+ }
131
+ // this sorting ensures the List method fulfils the contract of
132
+ // returning the most relevant items first
133
+ slices .SortFunc (expected , func (a , b list.Result ) int {
134
+ return cmp .Or (
135
+ // we want the results sorted in descending order by version
136
+ cmp .Compare (b .Version .Major , a .Version .Major ),
137
+ cmp .Compare (b .Version .Minor , a .Version .Minor ),
138
+ cmp .Compare (b .Version .Patch , a .Version .Patch ),
139
+ // ..and then in ascending order by platform
140
+ cmp .Compare (a .Platform .OS , b .Platform .OS ),
141
+ cmp .Compare (a .Platform .Arch , b .Platform .Arch ),
142
+ )
143
+ })
144
+
145
+ Expect (result ).To (HaveExactElements (expected ))
146
+ })
100
147
})
101
148
102
149
Context ("when downloads are enabled" , func () {
0 commit comments