Skip to content

Commit

Permalink
latest_version - use version constraint passed in.
Browse files Browse the repository at this point in the history
This uses the version constraint passed into the `LatestVersion` struct
to ensure the constraints are checked against the returned versions.
  • Loading branch information
bjhaid committed Oct 6, 2023
1 parent 77b2d8a commit 32273e9
Show file tree
Hide file tree
Showing 2 changed files with 15 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
13 changes: 12 additions & 1 deletion releases/latest_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,33 @@ 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")),
},
"1.14.1+ent.fips1402": &rjson.ProductVersion{
Version: version.Must(version.NewVersion("1.14.1+ent.fips1402")),
},
}
constraints, _ := version.NewConstraint("~> 1.14.0")

testCases := map[string]struct {
lv LatestVersion
expectedVersion string
}{
"oss": {
"oss1": {
lv: LatestVersion{
Product: product.Vault,
},
expectedVersion: "1.15.2",
},
"oss2": {
lv: LatestVersion{
Product: product.Vault,
Constraints: constraints,
},
expectedVersion: "1.14.1",
},
"enterprise": {
Expand Down

0 comments on commit 32273e9

Please sign in to comment.