diff --git a/bcs-services/bcs-bscp/pkg/sf-share/versioning.go b/bcs-services/bcs-bscp/pkg/sf-share/versioning.go index 8803ca6eb7..3c73a0f860 100644 --- a/bcs-services/bcs-bscp/pkg/sf-share/versioning.go +++ b/bcs-services/bcs-bscp/pkg/sf-share/versioning.go @@ -38,17 +38,17 @@ func IsAPIVersionMatch(ver *pbbase.Versioning) bool { return false } - if ver.Major > leastAPIVersion.Major { + if ver.Major < leastAPIVersion.Major { return false } if ver.Major == leastAPIVersion.Major { - if ver.Minor > leastAPIVersion.Minor { + if ver.Minor < leastAPIVersion.Minor { return false } if ver.Minor == leastAPIVersion.Minor { - if ver.Patch > leastAPIVersion.Patch { + if ver.Patch < leastAPIVersion.Patch { return false } } @@ -71,17 +71,17 @@ var leastSidecarVersion = &pbbase.Versioning{ // feed server's version request. func IsSidecarVersionMatch(ver *pbbase.Versioning) bool { - if ver.Major > leastSidecarVersion.Major { + if ver.Major < leastSidecarVersion.Major { return false } if ver.Major == leastSidecarVersion.Major { - if ver.Minor > leastSidecarVersion.Minor { + if ver.Minor < leastSidecarVersion.Minor { return false } if ver.Minor == leastSidecarVersion.Minor { - if ver.Patch > leastSidecarVersion.Patch { + if ver.Patch < leastSidecarVersion.Patch { return false } } diff --git a/bcs-services/bcs-bscp/pkg/sf-share/versioning_test.go b/bcs-services/bcs-bscp/pkg/sf-share/versioning_test.go index 8e75b4d7c5..f5b791f53d 100644 --- a/bcs-services/bcs-bscp/pkg/sf-share/versioning_test.go +++ b/bcs-services/bcs-bscp/pkg/sf-share/versioning_test.go @@ -18,105 +18,79 @@ import ( pbbase "bscp.io/pkg/protocol/core/base" ) -func TestIsVersionMatch(t *testing.T) { - with := &pbbase.Versioning{ +func TestIsAPIVersionMatch(t *testing.T) { + leastAPIVersion = &pbbase.Versioning{ Major: 3, Minor: 4, Patch: 5, } - leastAPIVersion = with - // matched test case. - test := &pbbase.Versioning{ - Major: 3, - Minor: 4, - Patch: 5, - } - - yes := IsAPIVersionMatch(test) - - if !yes { - t.Errorf("should matched, but not.") - return + testCases := []struct { + name string + ver *pbbase.Versioning + expected bool + }{ + { + name: "Major version mismatch", + ver: &pbbase.Versioning{ + Major: 2, + Minor: 4, + Patch: 5, + }, + expected: false, + }, + { + name: "Minor version mismatch", + ver: &pbbase.Versioning{ + Major: 3, + Minor: 3, + Patch: 5, + }, + expected: false, + }, + { + name: "Patch version mismatch", + ver: &pbbase.Versioning{ + Major: 3, + Minor: 4, + Patch: 4, + }, + expected: false, + }, + { + name: "Major version match", + ver: &pbbase.Versioning{ + Major: 3, + Minor: 4, + Patch: 5, + }, + expected: true, + }, + { + name: "Minor version match", + ver: &pbbase.Versioning{ + Major: 3, + Minor: 4, + Patch: 6, + }, + expected: true, + }, + { + name: "Patch version match", + ver: &pbbase.Versioning{ + Major: 3, + Minor: 5, + Patch: 5, + }, + expected: true, + }, } - test = &pbbase.Versioning{ - Major: 3, - Minor: 4, - Patch: 4, - } - - yes = IsAPIVersionMatch(test) - - if !yes { - t.Errorf("should matched, but not.") - return + for _, tc := range testCases { + result := IsAPIVersionMatch(tc.ver) + if result != tc.expected { + t.Errorf("Test %s failed, Expected %v, got %v", tc.name, tc.expected, result) + t.Fail() + } } - - test = &pbbase.Versioning{ - Major: 3, - Minor: 3, - Patch: 10, - } - - yes = IsAPIVersionMatch(test) - - if !yes { - t.Errorf("should matched, but not.") - return - } - - test = &pbbase.Versioning{ - Major: 2, - Minor: 10, - Patch: 10, - } - - yes = IsAPIVersionMatch(test) - - if !yes { - t.Errorf("should matched, but not.") - return - } - - // not match test case. - test = &pbbase.Versioning{ - Major: 3, - Minor: 5, - Patch: 0, - } - - yes = IsAPIVersionMatch(test) - - if yes { - t.Errorf("should not matched, but not.") - return - } - - test = &pbbase.Versioning{ - Major: 3, - Minor: 4, - Patch: 6, - } - - yes = IsAPIVersionMatch(test) - - if yes { - t.Errorf("should not matched, but not.") - return - } - - test = &pbbase.Versioning{ - Major: 4, - Minor: 0, - Patch: 0, - } - - yes = IsAPIVersionMatch(test) - - if yes { - t.Errorf("should not matched, but not.") - return - } - }