From 3decb85e5a262c4067403828bd9af95ade681265 Mon Sep 17 00:00:00 2001 From: AlkaidChen <362774405@qq.com> Date: Mon, 21 Aug 2023 11:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20SDK=20API=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8C=B9=E9=85=8D=E9=97=AE=E9=A2=98=20(#2464)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bcs-bscp/pkg/sf-share/versioning.go | 12 +- .../bcs-bscp/pkg/sf-share/versioning_test.go | 160 ++++++++---------- 2 files changed, 73 insertions(+), 99 deletions(-) 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 - } - }