-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-8851] Make options consistent across client pkgs
Change-Id: Ice87f4818aaafb7db1e23a872b4c9a500b82a438 Signed-off-by: Troy Ronda <[email protected]>
- Loading branch information
Showing
10 changed files
with
153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package channel | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core" | ||
fcmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestWithTargetURLsInvalid(t *testing.T) { | ||
ctx := setupMockTestContext("test", "Org1MSP") | ||
opt := WithTargetURLs("invalid") | ||
|
||
mockConfig := &fcmocks.MockConfig{} | ||
|
||
oConfig := &core.PeerConfig{ | ||
URL: "127.0.0.1:7050", | ||
} | ||
|
||
mockConfig.SetCustomPeerCfg(oConfig) | ||
ctx.SetConfig(mockConfig) | ||
|
||
opts := requestOptions{} | ||
err := opt(ctx, &opts) | ||
assert.NotNil(t, err, "Should have failed for invalid target peer") | ||
} | ||
|
||
func TestWithTargetURLsValid(t *testing.T) { | ||
ctx := setupMockTestContext("test", "Org1MSP") | ||
opt := WithTargetURLs("127.0.0.1:7050") | ||
|
||
mockConfig := &fcmocks.MockConfig{} | ||
|
||
pConfig1 := core.PeerConfig{ | ||
URL: "127.0.0.1:7050", | ||
} | ||
|
||
npConfig1 := core.NetworkPeer{ | ||
PeerConfig: pConfig1, | ||
MspID: "MYMSP", | ||
} | ||
|
||
pConfig2 := core.PeerConfig{ | ||
URL: "127.0.0.1:7051", | ||
} | ||
|
||
npConfig2 := core.NetworkPeer{ | ||
PeerConfig: pConfig2, | ||
MspID: "OTHERMSP", | ||
} | ||
|
||
mockConfig.SetCustomPeerCfg(&pConfig1) | ||
mockConfig.SetCustomNetworkPeerCfg([]core.NetworkPeer{npConfig2, npConfig1}) | ||
ctx.SetConfig(mockConfig) | ||
|
||
opts := requestOptions{} | ||
err := opt(ctx, &opts) | ||
assert.Nil(t, err, "Should have failed for invalid target peer") | ||
|
||
assert.Equal(t, 1, len(opts.Targets), "should have one peer") | ||
assert.Equal(t, pConfig1.URL, opts.Targets[0].URL(), "", "Wrong URL") | ||
assert.Equal(t, npConfig1.MspID, opts.Targets[0].MSPID(), "", "Wrong MSP") | ||
} | ||
|
||
func setupMockTestContext(userName string, mspID string) *fcmocks.MockContext { | ||
user := fcmocks.NewMockUserWithMSPID(userName, mspID) | ||
ctx := fcmocks.NewMockContext(user) | ||
return ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters