From 07808ad2119688037ef10c79a3779f46c367f5ce Mon Sep 17 00:00:00 2001 From: Sandra Vrtikapa Date: Mon, 12 Feb 2018 14:56:04 -0500 Subject: [PATCH] [FAB-7978] ResourceMgmt: Join channel with filter only Change-Id: Idf6b2c360a643ab66edb72025b3c279ea791123f Signed-off-by: Sandra Vrtikapa --- pkg/fabric-txn/resmgmtclient/resmgmt.go | 8 -------- pkg/fabric-txn/resmgmtclient/resmgmt_test.go | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/fabric-txn/resmgmtclient/resmgmt.go b/pkg/fabric-txn/resmgmtclient/resmgmt.go index a19aed8704..a1d60802bc 100644 --- a/pkg/fabric-txn/resmgmtclient/resmgmt.go +++ b/pkg/fabric-txn/resmgmtclient/resmgmt.go @@ -113,14 +113,6 @@ func (rc *ResourceMgmtClient) JoinChannel(channelID string, options ...resmgmt.O return errors.WithMessage(err, "failed to get opts for JoinChannel") } - //Default targets when targets are not provided in options - if len(opts.Targets) == 0 { - opts.Targets, err = rc.getDefaultTargets(rc.discovery) - if err != nil { - return errors.WithMessage(err, "failed to get default targets for JoinChannel") - } - } - targets, err := rc.calculateTargets(rc.discovery, opts.Targets, opts.TargetFilter) if err != nil { return errors.WithMessage(err, "failed to determine target peers for JoinChannel") diff --git a/pkg/fabric-txn/resmgmtclient/resmgmt_test.go b/pkg/fabric-txn/resmgmtclient/resmgmt_test.go index 046aa3ce53..40992d2bbb 100644 --- a/pkg/fabric-txn/resmgmtclient/resmgmt_test.go +++ b/pkg/fabric-txn/resmgmtclient/resmgmt_test.go @@ -145,7 +145,7 @@ func TestJoinChannelRequiredParameters(t *testing.T) { // Test missing default targets err = rc.JoinChannel("mychannel") - if err == nil { + if err == nil || !strings.Contains(err.Error(), "No targets available") { t.Fatalf("InstallCC should have failed with no default targets error") } @@ -167,16 +167,28 @@ func TestJoinChannelWithOptsRequiredParameters(t *testing.T) { // Test both targets and filter provided (error condition) err = rc.JoinChannel("mychannel", resmgmt.WithTargets(peers...), resmgmt.WithTargetFilter(&MSPFilter{mspID: "MspID"})) - if err == nil { + if err == nil || !strings.Contains(err.Error(), "If targets are provided, filter cannot be provided") { t.Fatalf("Should have failed if both target and filter provided") } - // Test missing default targets + // Test targets only + err = rc.JoinChannel("mychannel", resmgmt.WithTargets(peers...)) + if err != nil { + t.Fatalf(err.Error()) + } + + // Test filter only (filter has no match) err = rc.JoinChannel("mychannel", resmgmt.WithTargetFilter(&MSPFilter{mspID: "MspID"})) - if err == nil { + if err == nil || !strings.Contains(err.Error(), "No targets available") { t.Fatalf("InstallCC should have failed with no targets error") } + // Test filter only (filter has a match) + err = rc.JoinChannel("mychannel", resmgmt.WithTargetFilter(&MSPFilter{mspID: "Org1MSP"})) + if err != nil { + t.Fatalf(err.Error()) + } + } func TestJoinChannelDiscoveryError(t *testing.T) {