Skip to content

Commit

Permalink
LatestVersion - use version Constraints passed in (#159)
Browse files Browse the repository at this point in the history
* latest_version - use version constraint passed in.

This uses the version constraint passed into the `LatestVersion` struct
to ensure the constraints are checked against the returned versions.

* cleanup: use MustConstraint to inline constraint

---------

Co-authored-by: Radek Simko <[email protected]>
  • Loading branch information
bjhaid and radeksimko authored Oct 10, 2023
1 parent a7e09b6 commit eab6333
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion releases/latest_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ func (lv *LatestVersion) findLatestMatchingVersion(pvs rjson.ProductVersionsMap,
continue
}

versions = append(versions, pv.Version)
if vc.Check(pv.Version) {
versions = append(versions, pv.Version)
}
}

if len(versions) == 0 {
Expand Down
12 changes: 11 additions & 1 deletion releases/latest_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func TestLatestVersion_FindLatestMatchingVersion(t *testing.T) {
"1.14.1": &rjson.ProductVersion{
Version: version.Must(version.NewVersion("1.14.1")),
},
"1.15.2": &rjson.ProductVersion{
Version: version.Must(version.NewVersion("1.15.2")),
},
"1.14.1+ent": &rjson.ProductVersion{
Version: version.Must(version.NewVersion("1.14.1+ent")),
},
Expand All @@ -96,10 +99,17 @@ func TestLatestVersion_FindLatestMatchingVersion(t *testing.T) {
lv LatestVersion
expectedVersion string
}{
"oss": {
"oss1": {
lv: LatestVersion{
Product: product.Vault,
},
expectedVersion: "1.15.2",
},
"oss2": {
lv: LatestVersion{
Product: product.Vault,
Constraints: version.MustConstraints(version.NewConstraint("~> 1.14.0")),
},
expectedVersion: "1.14.1",
},
"enterprise": {
Expand Down

0 comments on commit eab6333

Please sign in to comment.