diff --git a/lib/upgrade/upgrade_common.go b/lib/upgrade/upgrade_common.go index 8ab467cc8..6e8f3581b 100644 --- a/lib/upgrade/upgrade_common.go +++ b/lib/upgrade/upgrade_common.go @@ -104,20 +104,26 @@ func CompareVersions(a, b string) Relation { for i := 0; i < minlen; i++ { if arel[i] < brel[i] { if i == 0 { + // major version difference + if arel[0] == 0 && brel[0] == 1 { + // special case, v0.x is equivalent in majorness to v1.x. + return Older + } return MajorOlder } - if i == 1 && arel[0] == 0 { - return MajorOlder - } + // minor or patch version difference return Older } if arel[i] > brel[i] { if i == 0 { + // major version difference + if arel[0] == 1 && brel[0] == 0 { + // special case, v0.x is equivalent in majorness to v1.x. + return Newer + } return MajorNewer } - if i == 1 && arel[0] == 0 { - return MajorNewer - } + // minor or patch version difference return Newer } } diff --git a/lib/upgrade/upgrade_test.go b/lib/upgrade/upgrade_test.go index 2d81f891b..5f688de0d 100644 --- a/lib/upgrade/upgrade_test.go +++ b/lib/upgrade/upgrade_test.go @@ -20,19 +20,21 @@ var versions = []struct { {"0.1.2", "0.1.2", Equal}, {"0.1.3", "0.1.2", Newer}, {"0.1.1", "0.1.2", Older}, - {"0.3.0", "0.1.2", MajorNewer}, - {"0.0.9", "0.1.2", MajorOlder}, + {"0.3.0", "0.1.2", Newer}, + {"0.0.9", "0.1.2", Older}, {"1.3.0", "1.1.2", Newer}, {"1.0.9", "1.1.2", Older}, {"2.3.0", "1.1.2", MajorNewer}, {"1.0.9", "2.1.2", MajorOlder}, - {"1.1.2", "0.1.2", MajorNewer}, - {"0.1.2", "1.1.2", MajorOlder}, + {"1.1.2", "0.1.2", Newer}, + {"0.1.2", "1.1.2", Older}, + {"2.1.2", "0.1.2", MajorNewer}, + {"0.1.2", "2.1.2", MajorOlder}, {"0.1.10", "0.1.9", Newer}, - {"0.10.0", "0.2.0", MajorNewer}, + {"0.10.0", "0.2.0", Newer}, {"30.10.0", "4.9.0", MajorNewer}, {"0.9.0-beta7", "0.9.0-beta6", Newer}, - {"0.9.0-beta7", "1.0.0-alpha", MajorOlder}, + {"0.9.0-beta7", "1.0.0-alpha", Older}, {"1.0.0-alpha", "1.0.0-alpha.1", Older}, {"1.0.0-alpha.1", "1.0.0-alpha.beta", Older}, {"1.0.0-alpha.beta", "1.0.0-beta", Older}, @@ -73,6 +75,8 @@ func TestSelectedRelease(t *testing.T) { }{ // Within the same "major" (minor, in this case) select the newest {"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.12.26"}, "v0.12.26"}, + {"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.13.0"}, + {"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v1.0.0"}, "v1.0.0"}, // Do no select beta versions when we are not allowed to {"v0.12.24", false, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.26"}, {"v0.12.24-beta.0", false, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.26"}, @@ -80,7 +84,7 @@ func TestSelectedRelease(t *testing.T) { {"v0.12.24", true, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.27-beta.42"}, {"v0.12.24-beta.0", true, []string{"v0.12.26", "v0.12.27-beta.42"}, "v0.12.27-beta.42"}, // Select the best within the current major when there is a minor upgrade available - {"v0.12.24", false, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.12.25"}, + {"v0.12.24", false, []string{"v1.12.23", "v1.12.24", "v1.14.2", "v2.0.0"}, "v1.14.2"}, {"v1.12.24", false, []string{"v1.12.23", "v1.12.24", "v1.14.2", "v2.0.0"}, "v1.14.2"}, // Select the next major when we are at the best minor {"v0.12.25", true, []string{"v0.12.23", "v0.12.24", "v0.12.25", "v0.13.0"}, "v0.13.0"},