-
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.
This option adds a WithTargetURLs option. This new options is similar to WithTargets, but only a URL is required. The peer object is created from the InfraProvider based on configuration associated to the URL. Change-Id: I188c8b8726e8bbc224ea23c1bd6a62333edc9efd Signed-off-by: Troy Ronda <[email protected]>
- Loading branch information
Showing
11 changed files
with
312 additions
and
32 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
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 ledger | ||
|
||
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 := setupTestContext("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 := setupTestContext("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 setupTestContext(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package resmgmt | ||
|
||
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 := setupTestContext("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 := setupTestContext("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") | ||
} |
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
Oops, something went wrong.