Merge pull request #19977 from findkim/filter-prerelease-provider-protocol-mismatch

Prerelease versions are filtered for plugin protocol mismatches
This commit is contained in:
Kim Ngo 2019-01-11 14:59:14 -06:00 committed by GitHub
commit e168d81894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 1 deletions

View File

@ -416,12 +416,18 @@ func (i *ProviderInstaller) listProviderDownloadURLs(name, version string) (*res
}
// findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match.
//
// Prerelease versions are filtered.
func (i *ProviderInstaller) findClosestProtocolCompatibleVersion(versions []*response.TerraformProviderVersion) (*response.TerraformProviderVersion, error) {
// Loop through all the provider versions to find the earliest and latest
// versions that match the installer protocol to then select the closest of the two
var latest, earliest *response.TerraformProviderVersion
for _, version := range versions {
// Prereleases are filtered and will not be suggested
v, err := VersionStr(version.Version).Parse()
if err != nil || v.IsPrerelease() {
continue
}
if err := i.checkPluginProtocol(version); err == nil {
if earliest == nil {
// Found the first provider version with compatible protocol

View File

@ -314,6 +314,63 @@ func TestFindClosestProtocolCompatibleVersion(t *testing.T) {
},
"2.5.0",
false,
}, {
"compatible prereleses are filtered",
5,
[]*response.TerraformProviderVersion{
&response.TerraformProviderVersion{
Version: "2.0.0-alpha",
Protocols: []string{"4.0", "5.0"},
},
},
"",
true,
}, {
"suggests latest non-prerelease",
4,
[]*response.TerraformProviderVersion{
&response.TerraformProviderVersion{
Version: "2.0.0-alpha",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "2.0.0",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "2.5.0-pre",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "2.5.0",
Protocols: []string{"4.0", "5.0"},
},
},
"2.5.0",
false,
}, {
"suggests earliest non-prerelease",
5,
[]*response.TerraformProviderVersion{
&response.TerraformProviderVersion{
Version: "2.0.0-alpha",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "2.0.0",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "2.6.0",
Protocols: []string{"4.0", "5.0"},
},
&response.TerraformProviderVersion{
Version: "3.0.0",
Protocols: []string{"5.0"},
},
},
"2.0.0",
false,
},
}

View File

@ -55,6 +55,11 @@ func (v Version) Equal(other Version) bool {
return v.raw.Equal(other.raw)
}
// IsPrerelease determines if version is a prerelease
func (v Version) IsPrerelease() bool {
return v.raw.Prerelease() != ""
}
// MinorUpgradeConstraintStr returns a ConstraintStr that would permit
// minor upgrades relative to the receiving version.
func (v Version) MinorUpgradeConstraintStr() ConstraintStr {