-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return single package when multiple indexers are used #849
Changes from 1 commit
bf0107c
13f6a10
98f7a74
096ba49
7d5117c
0116753
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/package-registry/packages" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLatestPackagesVersion(t *testing.T) { | ||
newPackage := func(name string, version string) *packages.Package { | ||
p := new(packages.Package) | ||
p.Name = name | ||
p.Version = version | ||
return p | ||
} | ||
|
||
cases := []struct { | ||
title string | ||
source packages.Packages | ||
expected packages.Packages | ||
}{ | ||
{ | ||
title: "single package", | ||
source: packages.Packages{ | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
expected: packages.Packages{ | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
}, | ||
{ | ||
title: "single package sorted versions", | ||
source: packages.Packages{ | ||
newPackage("foo", "1.2.3"), | ||
newPackage("foo", "1.2.2"), | ||
newPackage("foo", "1.2.1"), | ||
}, | ||
expected: packages.Packages{ | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
}, | ||
{ | ||
title: "single package unsorted versions", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about adding a case where both indexers contain the same package version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the case where both indexers contain the same package version, what would the behavior be for a query with I would think even in this case the response should only contain one item for that package version. The reason being that the other APIs don't provide a way to differentiate between the two items (e.g. the only specifiers are name and version in the download request There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that in that case we have to decide that some indexers have precendence over the others, I will take a look to this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a change so indexes defined later have precedence over the ones defined earlier. I have made that because currently we are defining the zip indexer, with support for signatures, after the plain file indexer, so now if a package is in both indexers, the zip with signature will have precedence. |
||
source: packages.Packages{ | ||
newPackage("foo", "1.2.2"), | ||
newPackage("foo", "1.2.1"), | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
expected: packages.Packages{ | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
}, | ||
{ | ||
title: "multiple packages with multiple versions", | ||
source: packages.Packages{ | ||
newPackage("foo", "1.2.2"), | ||
newPackage("bar", "1.2.1"), | ||
newPackage("bar", "1.2.2"), | ||
newPackage("foo", "1.2.1"), | ||
newPackage("bar", "1.2.3"), | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
expected: packages.Packages{ | ||
newPackage("bar", "1.2.3"), | ||
newPackage("foo", "1.2.3"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.title, func(t *testing.T) { | ||
result := latestPackagesVersion(c.source) | ||
assert.EqualValues(t, c.expected, result) | ||
}) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call
sort.Sort
on the source, it won't alter the originalpackages
slice? I'm double-checking if this is concurrency-safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will modify the
packages
slice defined in theCombinerIndexer.Get
, that is built on every call to this method and shouldn't be used concurrently in any other place.