Skip to content

Commit

Permalink
修复 SDK API 版本匹配问题 (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaidChan authored Aug 21, 2023
1 parent 0cb10e7 commit 3decb85
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 99 deletions.
12 changes: 6 additions & 6 deletions bcs-services/bcs-bscp/pkg/sf-share/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
160 changes: 67 additions & 93 deletions bcs-services/bcs-bscp/pkg/sf-share/versioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

0 comments on commit 3decb85

Please sign in to comment.