diff --git a/test/util/velero/install.go b/test/util/velero/install.go index da57ef19e..e2c57392e 100644 --- a/test/util/velero/install.go +++ b/test/util/velero/install.go @@ -365,7 +365,7 @@ func VersionNoOlderThan(version string, targetVersion string) (bool, error) { matches := tagRe.FindStringSubmatch(targetVersion) targetMajor := matches[1] targetMinor := matches[2] - if major > targetMajor && minor >= targetMinor { + if major >= targetMajor && minor >= targetMinor { return true, nil } else { return false, nil diff --git a/test/util/velero/install_test.go b/test/util/velero/install_test.go new file mode 100644 index 000000000..8ea51bd40 --- /dev/null +++ b/test/util/velero/install_test.go @@ -0,0 +1,65 @@ +/* +Copyright the Velero contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package velero + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_VersionNoOlderThan(t *testing.T) { + type versionTest struct { + caseName string + version string + targetVersion string + result bool + err error + } + tests := []versionTest{ + { + caseName: "branch version compare", + version: "release-1.18", + targetVersion: "v1.16", + result: true, + err: nil, + }, + { + caseName: "tag version compare", + version: "v1.18.0", + targetVersion: "v1.16", + result: true, + err: nil, + }, + { + caseName: "main version compare", + version: "main", + targetVersion: "v1.15", + result: true, + err: nil, + }, + } + + for _, test := range tests { + t.Run(test.caseName, func(t *testing.T) { + res, err := VersionNoOlderThan(test.version, test.targetVersion) + + require.Equal(t, test.err, err) + require.Equal(t, test.result, res) + }) + } +}