Skip to content

Commit

Permalink
[FAB-7978] ResourceMgmt: Join channel with filter only
Browse files Browse the repository at this point in the history
Change-Id: Idf6b2c360a643ab66edb72025b3c279ea791123f
Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Feb 12, 2018
1 parent 1fd4d4d commit 07808ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 0 additions & 8 deletions pkg/fabric-txn/resmgmtclient/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions pkg/fabric-txn/resmgmtclient/resmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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) {
Expand Down

0 comments on commit 07808ad

Please sign in to comment.