@@ -164,7 +164,7 @@ func TestMatchRequested(t *testing.T) {
164164 name : "exact name match with .rpm extension" ,
165165 requests : []string {"test-package" },
166166 all : []ospackage.PackageInfo {
167- {Name : "test-package.rpm " , Arch : "x86_64" },
167+ {Name : "test-package" , Arch : "x86_64" , Version : "1.0-1 " },
168168 },
169169 expectError : false ,
170170 expectCount : 1 ,
@@ -173,8 +173,8 @@ func TestMatchRequested(t *testing.T) {
173173 name : "version prefix match" ,
174174 requests : []string {"acl" },
175175 all : []ospackage.PackageInfo {
176- {Name : "acl- 2.3.1-2.el8" , Arch : "x86_64" },
177- {Name : "acl-dev" , Arch : "x86_64" }, // Should not match - not a version
176+ {Name : "acl" , Version : " 2.3.1-2.el8" , Arch : "x86_64" },
177+ {Name : "acl-dev" , Arch : "x86_64" }, // Should not match - different package
178178 },
179179 expectError : false ,
180180 expectCount : 1 ,
@@ -183,7 +183,7 @@ func TestMatchRequested(t *testing.T) {
183183 name : "release prefix match" ,
184184 requests : []string {"package" },
185185 all : []ospackage.PackageInfo {
186- {Name : "package- 1.0.0" , Arch : "x86_64" },
186+ {Name : "package" , Version : " 1.0.0" , Arch : "x86_64" },
187187 },
188188 expectError : false ,
189189 expectCount : 1 ,
@@ -211,12 +211,12 @@ func TestMatchRequested(t *testing.T) {
211211 name : "multiple candidates - pick highest" ,
212212 requests : []string {"package" },
213213 all : []ospackage.PackageInfo {
214- {Name : "package- 1.0.0" , Arch : "x86_64" },
215- {Name : "package- 2.0.0" , Arch : "x86_64" },
216- {Name : "package- 1.5.0" , Arch : "x86_64" },
214+ {Name : "package" , Version : " 1.0.0" , Arch : "x86_64" },
215+ {Name : "package" , Version : " 2.0.0" , Arch : "x86_64" },
216+ {Name : "package" , Version : " 1.5.0" , Arch : "x86_64" },
217217 },
218218 expectError : false ,
219- expectCount : 1 , // Should pick package- 2.0.0 (highest lex sort )
219+ expectCount : 1 , // Should pick package with version 2.0.0 (exact name match, first found )
220220 },
221221 }
222222
@@ -240,136 +240,6 @@ func TestMatchRequested(t *testing.T) {
240240 }
241241}
242242
243- func TestIsAcceptedChar (t * testing.T ) {
244- testCases := []struct {
245- name string
246- input string
247- expected bool
248- }{
249- {
250- name : "empty string" ,
251- input : "" ,
252- expected : false ,
253- },
254- {
255- name : "only digits" ,
256- input : "123" ,
257- expected : true ,
258- },
259- {
260- name : "digits with dash" ,
261- input : "1-2-3" ,
262- expected : true ,
263- },
264- {
265- name : "contains letters" ,
266- input : "1a2" ,
267- expected : false ,
268- },
269- {
270- name : "contains special chars" ,
271- input : "1.2" ,
272- expected : false ,
273- },
274- {
275- name : "only dash" ,
276- input : "-" ,
277- expected : true ,
278- },
279- {
280- name : "mixed valid chars" ,
281- input : "123-456-789" ,
282- expected : true ,
283- },
284- }
285-
286- for _ , tc := range testCases {
287- t .Run (tc .name , func (t * testing.T ) {
288- // Since isAcceptedChar is not exported, we need to test it indirectly through isValidVersionFormat
289- // or we need to make it exported for testing. For now, let's test it indirectly.
290- t .Skip ("isAcceptedChar is not exported - testing indirectly through isValidVersionFormat" )
291- })
292- }
293- }
294-
295- func TestIsValidVersionFormat (t * testing.T ) {
296- testCases := []struct {
297- name string
298- input string
299- expected bool
300- }{
301- {
302- name : "empty string" ,
303- input : "" ,
304- expected : false ,
305- },
306- {
307- name : "simple version" ,
308- input : "1.0.0" ,
309- expected : true ,
310- },
311- {
312- name : "version with dash" ,
313- input : "1-2.el8" ,
314- expected : true ,
315- },
316- {
317- name : "version without dot" ,
318- input : "123" ,
319- expected : true ,
320- },
321- {
322- name : "invalid version with letters" ,
323- input : "abc.def" ,
324- expected : false ,
325- },
326- {
327- name : "version starting with letter" ,
328- input : "a1.0.0" ,
329- expected : false ,
330- },
331- {
332- name : "complex version" ,
333- input : "2-3-1.el8_5" ,
334- expected : true ,
335- },
336- }
337-
338- for _ , tc := range testCases {
339- t .Run (tc .name , func (t * testing.T ) {
340- // Since isValidVersionFormat is not exported, we'll test it indirectly
341- // Let's create a test that exercises this through MatchRequested
342- all := []ospackage.PackageInfo {
343- {Name : fmt .Sprintf ("package-%s" , tc .input ), Arch : "x86_64" },
344- }
345-
346- result , err := rpmutils .MatchRequested ([]string {"package" }, all )
347-
348- if tc .expected {
349- // If the version format is valid, we should find a match
350- if err != nil || len (result ) == 0 {
351- t .Errorf ("Expected to find match for valid version format %q" , tc .input )
352- }
353- } else {
354- // If the version format is invalid, we should not find a match (unless it's exact)
355- if err == nil && len (result ) > 0 && result [0 ].Name != "package" {
356- // Only fail if we found a match that wasn't exact
357- exactMatch := false
358- for _ , pkg := range all {
359- if pkg .Name == "package" {
360- exactMatch = true
361- break
362- }
363- }
364- if ! exactMatch {
365- t .Errorf ("Expected no match for invalid version format %q, but got: %v" , tc .input , result )
366- }
367- }
368- }
369- })
370- }
371- }
372-
373243func TestValidate (t * testing.T ) {
374244 // Save original global variables
375245 originalRepoCfg := rpmutils .RepoCfg
0 commit comments