Skip to content

Commit

Permalink
Fixed capability version matcher for cases with 3 or more levels (#57)
Browse files Browse the repository at this point in the history
* Fixed capability version matcher for cases with 3 or more levels (V1_4_2, V2_0_1etc)

Signed-off-by: kopaihorodskyi <a542e9b744bed>

* Capability matcher: added test case for versions like V1, V2, V3 ...

Signed-off-by: kopaihorodskyi <a542e9b744bed>

* Capability matcher: fixed typos

Signed-off-by: kopaihorodskyi <a542e9b744bed>
  • Loading branch information
kopaygorodsky committed Mar 2, 2020
1 parent 4919c92 commit 8bcbcfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/fab/chconfig/chconfig.go
Expand Up @@ -32,7 +32,7 @@ var logger = logging.NewLogger("fabsdk/fab")

//overrideRetryHandler is private and used for unit-tests to test query retry behaviors
var overrideRetryHandler retry.Handler
var versionCapabilityPattern = regexp.MustCompile(`^V(\d+)_(\d+)$`)
var versionCapabilityPattern = regexp.MustCompile(`^V(\d+(_\d+?)*)$`)

// Opts contains options for retrieving channel configuration
type Opts struct {
Expand Down
18 changes: 12 additions & 6 deletions pkg/fab/chconfig/chconfig_test.go
Expand Up @@ -10,8 +10,8 @@ import (
"path/filepath"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"

"time"

Expand Down Expand Up @@ -288,11 +288,15 @@ func TestResolveOptsDefaultValuesWithInvalidChannel(t *testing.T) {
}

func TestCapabilities(t *testing.T) {
capability1 := "V1_1_PVTDATA_EXPERIMENTAL"
capability2 := "V1_1_RESOURCETREE_EXPERIMENTAL"
pvtExpCapability := "V1_1_PVTDATA_EXPERIMENTAL"
resourceTreeExpCapability := "V1_1_RESOURCETREE_EXPERIMENTAL"
v1_12Capability := "V1_12"
V1_4Capability := "V1_4"
V1_4_2Capability := "V1_4_2"
v2_0Capability := "V2_0"
v2_1Capability := "V2_1"
V3Capability := "V3"
V3_1Capability := "V3_1"

builder := &mocks.MockConfigBlockBuilder{
MockConfigGroupBuilder: mocks.MockConfigGroupBuilder{
Expand All @@ -305,7 +309,7 @@ func TestCapabilities(t *testing.T) {
RootCA: validRootCA,
ChannelCapabilities: []string{fab.V1_1Capability},
OrdererCapabilities: []string{fab.V1_1Capability, v2_0Capability},
ApplicationCapabilities: []string{fab.V1_2Capability, capability1},
ApplicationCapabilities: []string{fab.V1_2Capability, pvtExpCapability, V3_1Capability, V1_4_2Capability},
},
Index: 0,
LastConfigIndex: 0,
Expand All @@ -321,8 +325,10 @@ func TestCapabilities(t *testing.T) {
assert.Falsef(t, chConfig.HasCapability(fab.OrdererGroupKey, v2_1Capability), "not expecting orderer capability", v2_1Capability)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, fab.V1_2Capability), "expecting application capability [%s]", fab.V1_2Capability)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, fab.V1_1Capability), "expecting application capability [%s] since [%s] is supported", fab.V1_1Capability, fab.V1_2Capability)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, capability1), "expecting application capability [%s]", capability1)
assert.Falsef(t, chConfig.HasCapability(fab.ApplicationGroupKey, capability2), "not expecting application capability [%s]", capability2)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, pvtExpCapability), "expecting application capability [%s]", pvtExpCapability)
assert.Falsef(t, chConfig.HasCapability(fab.ApplicationGroupKey, resourceTreeExpCapability), "not expecting application capability [%s]", resourceTreeExpCapability)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, V3Capability), "expecting application capability [%s]", V3Capability)
assert.Truef(t, chConfig.HasCapability(fab.ApplicationGroupKey, V1_4Capability), "expecting application capability [%s]", V1_4Capability)
}

func testResolveOptsDefaultValues(t *testing.T, channelID string) {
Expand Down

0 comments on commit 8bcbcfb

Please sign in to comment.