From 88455b489c5f7dfe710e9147cea309ba240d5303 Mon Sep 17 00:00:00 2001 From: Bob Stasyszyn Date: Thu, 14 Jun 2018 15:47:09 -0400 Subject: [PATCH] [FAB-10649] Fix local integration tests for v1.2 The Fabric Selection service now retrieves the URL of the peer from endpoint config before applying filters. Also, various integration tests needed to be changed in order to work with local config/entity matchers. Change-Id: I62ca6ad9e526d94e46ad09963ae29430d59f7569 Signed-off-by: Bob Stasyszyn --- .../fabricselection/fabricselection.go | 2 +- .../fabricselection/selection_test.go | 46 +++-- .../fabricselection/selectionfilter.go | 27 ++- .../local_entity_matchers_bootstrap.yaml | 37 ++++ .../local_orderers_peers_ca_bootstrap.yaml | 183 ++++++++++++++++++ test/integration/env.go | 18 +- .../orgs/multiple_orgs_minconfig_test.go | 11 +- test/integration/sdk/fabricselection_test.go | 56 ++++-- test/integration/sdk/sdk_dyndiscovery_test.go | 6 +- 9 files changed, 323 insertions(+), 63 deletions(-) create mode 100755 test/fixtures/config/overrides/local_entity_matchers_bootstrap.yaml create mode 100755 test/fixtures/config/overrides/local_orderers_peers_ca_bootstrap.yaml diff --git a/pkg/client/common/selection/fabricselection/fabricselection.go b/pkg/client/common/selection/fabricselection/fabricselection.go index 03728700c8..1afe736633 100644 --- a/pkg/client/common/selection/fabricselection/fabricselection.go +++ b/pkg/client/common/selection/fabricselection/fabricselection.go @@ -120,7 +120,7 @@ func (s *Service) GetEndorsersForChaincode(chaincodes []*fab.ChaincodeCall, opts params := options.NewParams(opts) - endpoints, err := chResponse.Endorsers(asInvocationChain(chaincodes), newSelector(params.PrioritySelector), newFilter(params.PeerFilter, peers)) + endpoints, err := chResponse.Endorsers(asInvocationChain(chaincodes), newSelector(s.ctx, params.PrioritySelector), newFilter(s.ctx, params.PeerFilter, peers)) if err != nil { return nil, errors.Wrap(err, "error getting endorsers from channel response") } diff --git a/pkg/client/common/selection/fabricselection/selection_test.go b/pkg/client/common/selection/fabricselection/selection_test.go index 540930ec25..9bc4e0c09a 100644 --- a/pkg/client/common/selection/fabricselection/selection_test.go +++ b/pkg/client/common/selection/fabricselection/selection_test.go @@ -52,25 +52,13 @@ var ( peer1Org3 = mocks.NewMockPeer("p31", peer1Org3URL) peer2Org3 = mocks.NewMockPeer("p32", peer2Org3URL) - peerConfigOrg1 = fab.NetworkPeer{ - PeerConfig: fab.PeerConfig{ - URL: peer1Org1URL, - }, - MSPID: mspID1, - } - peerConfigOrg2 = fab.NetworkPeer{ - PeerConfig: fab.PeerConfig{ - URL: peer1Org2URL, - }, - MSPID: mspID2, - } channelPeers = []fab.ChannelPeer{ - { - NetworkPeer: peerConfigOrg1, - }, - { - NetworkPeer: peerConfigOrg2, - }, + {NetworkPeer: newPeerConfig(peer1Org1URL, mspID1)}, + {NetworkPeer: newPeerConfig(peer2Org1URL, mspID1)}, + {NetworkPeer: newPeerConfig(peer1Org2URL, mspID2)}, + {NetworkPeer: newPeerConfig(peer2Org2URL, mspID2)}, + {NetworkPeer: newPeerConfig(peer1Org3URL, mspID3)}, + {NetworkPeer: newPeerConfig(peer2Org3URL, mspID3)}, } peer1Org1Endpoint = &discmocks.MockDiscoveryPeerEndpoint{ @@ -191,10 +179,10 @@ func TestSelection(t *testing.T) { options.WithPrioritySelector(func(peer1, peer2 fab.Peer) int { // Return peers in alphabetical order if peer1.URL() < peer2.URL() { - return 1 + return -1 } if peer1.URL() > peer2.URL() { - return -1 + return 1 } return 0 }), @@ -280,3 +268,21 @@ func (c *config) ChannelPeers(name string) ([]fab.ChannelPeer, bool) { } return c.peers, true } + +func (c *config) PeerConfig(nameOrURL string) (*fab.PeerConfig, bool) { + for _, peer := range c.peers { + if peer.URL == nameOrURL { + return &peer.NetworkPeer.PeerConfig, true + } + } + return nil, false +} + +func newPeerConfig(url, mspID string) fab.NetworkPeer { + return fab.NetworkPeer{ + PeerConfig: fab.PeerConfig{ + URL: url, + }, + MSPID: mspID, + } +} diff --git a/pkg/client/common/selection/fabricselection/selectionfilter.go b/pkg/client/common/selection/fabricselection/selectionfilter.go index e765bfdce7..e95fea3e9a 100644 --- a/pkg/client/common/selection/fabricselection/selectionfilter.go +++ b/pkg/client/common/selection/fabricselection/selectionfilter.go @@ -11,16 +11,19 @@ import ( discclient "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/discovery/client" "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/options" + contextAPI "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" ) type selectionFilter struct { + ctx contextAPI.Client peers []fab.Peer filter options.PeerFilter } -func newFilter(filter options.PeerFilter, peers []fab.Peer) *selectionFilter { +func newFilter(ctx contextAPI.Client, filter options.PeerFilter, peers []fab.Peer) *selectionFilter { return &selectionFilter{ + ctx: ctx, peers: peers, filter: filter, } @@ -29,7 +32,7 @@ func newFilter(filter options.PeerFilter, peers []fab.Peer) *selectionFilter { func (s *selectionFilter) Exclude(endpoint discclient.Peer) bool { logger.Debugf("Calling peer filter on endpoint [%s]", endpoint.AliveMessage.GetAliveMsg().Membership.Endpoint) - peer := asPeerValue(&endpoint) + peer := asPeerValue(s.ctx, &endpoint) // The peer must be included in the set of peers returned from fab.DiscoveryService. // (Note that DiscoveryService may return a filtered set of peers, depending on how the @@ -49,25 +52,35 @@ func (s *selectionFilter) Exclude(endpoint discclient.Peer) bool { } type prioritySelector struct { + ctx contextAPI.Client selector options.PrioritySelector } -func newSelector(selector options.PrioritySelector) discclient.PrioritySelector { +func newSelector(ctx contextAPI.Client, selector options.PrioritySelector) discclient.PrioritySelector { if selector != nil { - return &prioritySelector{selector: selector} + return &prioritySelector{ctx: ctx, selector: selector} } return discclient.PrioritiesByHeight } func (s *prioritySelector) Compare(endpoint1, endpoint2 discclient.Peer) discclient.Priority { logger.Debugf("Calling priority selector on endpoint1 [%s] and endpoint2 [%s]", endpoint1.AliveMessage.GetAliveMsg().Membership.Endpoint, endpoint2.AliveMessage.GetAliveMsg().Membership.Endpoint) - return discclient.Priority(s.selector(asPeerValue(&endpoint1), asPeerValue(&endpoint2))) + return discclient.Priority(s.selector(asPeerValue(s.ctx, &endpoint1), asPeerValue(s.ctx, &endpoint2))) } // asPeerValue converts the discovery endpoint into a light-weight peer value (i.e. without the GRPC config) // so that it may used by a peer filter -func asPeerValue(endpoint *discclient.Peer) fab.Peer { - url := endpoint.AliveMessage.GetAliveMsg().Membership.Endpoint +func asPeerValue(ctx contextAPI.Client, endpoint *discclient.Peer) fab.Peer { + url := endpoint.AliveMessage.GetAliveMsg().GetMembership().Endpoint + + // Get the mapped URL of the peer + peerConfig, found := ctx.EndpointConfig().PeerConfig(url) + if found { + url = peerConfig.URL + } else { + logger.Warnf("Peer config not found for url [%s]", url) + } + return &peerEndpointValue{ mspID: endpoint.MSPID, url: url, diff --git a/test/fixtures/config/overrides/local_entity_matchers_bootstrap.yaml b/test/fixtures/config/overrides/local_entity_matchers_bootstrap.yaml new file mode 100755 index 0000000000..d76e483d2d --- /dev/null +++ b/test/fixtures/config/overrides/local_entity_matchers_bootstrap.yaml @@ -0,0 +1,37 @@ +# +# Copyright SecureKey Technologies Inc. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +entityMatchers: + peer: + - pattern: (\w+).org1.example.com:(\d+) + urlSubstitutionExp: localhost:$2 + sslTargetOverrideUrlSubstitutionExp: $1.org1.example.com + mappedHost: local.peer0.org1.example.com + + - pattern: peer0.org2.example.com:8051 + urlSubstitutionExp: localhost:8051 + sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com + mappedHost: local.peer0.org2.example.com + + orderer: + - pattern: (\w+).example.(\w+) + urlSubstitutionExp: localhost:7050 + sslTargetOverrideUrlSubstitutionExp: orderer.example.com + mappedHost: local.orderer.example.com + + - pattern: (\w+).example.(\w+):(\d+) + urlSubstitutionExp: localhost:7050 + sslTargetOverrideUrlSubstitutionExp: orderer.example.com + mappedHost: local.orderer.example.com + + certificateAuthority: + - pattern: (\w+).org1.example.(\w+) + urlSubstitutionExp: https://localhost:7054 + mappedHost: local.ca.org1.example.com + + - pattern: (\w+).org2.example.(\w+) + urlSubstitutionExp: https://localhost:8054 + mappedHost: local.ca.org2.example.com diff --git a/test/fixtures/config/overrides/local_orderers_peers_ca_bootstrap.yaml b/test/fixtures/config/overrides/local_orderers_peers_ca_bootstrap.yaml new file mode 100755 index 0000000000..754b1b86a7 --- /dev/null +++ b/test/fixtures/config/overrides/local_orderers_peers_ca_bootstrap.yaml @@ -0,0 +1,183 @@ +# +# Copyright SecureKey Technologies Inc. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# +# +# The network connection profile provides client applications the information about the target +# blockchain network that are necessary for the applications to interact with it. These are all +# knowledge that must be acquired from out-of-band sources. This file provides such a source. +# + +# +# list of participating organizations in this network +# +organizations: + org1: + mspid: Org1MSP + + # This org's MSP store (absolute path or relative to client.cryptoconfig) + cryptoPath: peerOrganizations/org1.example.com/users/{username}@org1.example.com/msp + + peers: + - local.peer0.org1.example.com + + org2: + mspid: Org2MSP + + # This org's MSP store (absolute path or relative to client.cryptoconfig) + cryptoPath: peerOrganizations/org2.example.com/users/{username}@org2.example.com/msp + + peers: + - local.peer0.org2.example.com + + # Orderer Org name + ordererorg: + # Membership Service Provider ID for this organization + mspID: "OrdererOrg" + + # Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode) + cryptoPath: ordererOrganizations/example.com/users/{username}@example.com/msp + + +channels: + # multi-org test channel + orgchannel: + + # anchor peers only for the bootstrap config is required, other org's peers will be discovered + peers: + local.peer0.org1.example.com: + endorsingPeer: true + chaincodeQuery: true + ledgerQuery: true + eventSource: true + + local.peer0.org2.example.com: + endorsingPeer: true + chaincodeQuery: true + ledgerQuery: true + eventSource: true + + policies: + queryChannelConfig: + minResponses: 1 + maxTargets: 1 + retryOpts: + attempts: 5 + initialBackoff: 500ms + maxBackoff: 5s + backoffFactor: 2.0 + +# +# List of orderers to send transaction and channel create/update requests to. For the time +# being only one orderer is needed. If more than one is defined, which one get used by the +# SDK is implementation specific. Consult each SDK's documentation for its handling of orderers. +# +orderers: + local.orderer.example.com: + url: orderer.example.com:7050 + + # these are standard properties defined by the gRPC library + # they will be passed in as-is to gRPC client constructor + grpcOptions: + ssl-target-name-override: orderer.example.com + # These parameters should be set in coordination with the keepalive policy on the server, + # as incompatible settings can result in closing of connection. + # When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled + keep-alive-time: 0s + keep-alive-timeout: 20s + keep-alive-permit: false + fail-fast: false + # allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs + allow-insecure: false + + tlsCACerts: + # Certificate location absolute path + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem + +# +# List of peers to send various requests to, including endorsement, query +# and event listener registration. +# +peers: + local.peer0.org1.example.com: + # this URL is used to send endorsement and query requests + url: localhost:7051 + + grpcOptions: + ssl-target-name-override: peer0.org1.example.com + # These parameters should be set in coordination with the keepalive policy on the server, + # as incompatible settings can result in closing of connection. + # When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled + keep-alive-time: 0s + keep-alive-timeout: 20s + keep-alive-permit: false + fail-fast: false + # allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs + allow-insecure: false + + tlsCACerts: + # Certificate location absolute path + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem + + local.peer0.org2.example.com: + url: localhost:8051 + grpcOptions: + ssl-target-name-override: peer0.org2.example.com + # These parameters should be set in coordination with the keepalive policy on the server, + # as incompatible settings can result in closing of connection. + # When duration of the 'keep-alive-time' is set to 0 or less the keep alive client parameters are disabled + keep-alive-time: 0s + keep-alive-timeout: 20s + keep-alive-permit: false + fail-fast: false + # allow-insecure will be taken into consideration if address has no protocol defined, if true then grpc or else grpcs + allow-insecure: false + + tlsCACerts: + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem + +# +# Fabric-CA is a special kind of Certificate Authority provided by Hyperledger Fabric which allows +# certificate management to be done via REST APIs. Application may choose to use a standard +# Certificate Authority instead of Fabric-CA, in which case this section would not be specified. +# +certificateAuthorities: + local.ca.org1.example.com: + url: https://ca.org1.example.com:7054 + tlsCACerts: + # Comma-Separated list of paths + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/ca_root.pem + # Client key and cert for SSL handshake with Fabric CA + client: + key: + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client-key.pem + cert: + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client.pem + + # Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is + # needed to enroll and invoke new users. + registrar: + enrollId: admin + enrollSecret: adminpw + # [Optional] The optional name of the CA. + caName: ca.org1.example.com + local.ca.org2.example.com: + url: https://ca.org2.example.com:8054 + tlsCACerts: + # Comma-Separated list of paths + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/ca_root.pem + # Client key and cert for SSL handshake with Fabric CA + client: + key: + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client-key.pem + cert: + path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/fabricca/tls/certs/client/client_fabric_client.pem + + # Fabric-CA supports dynamic user enrollment via REST APIs. A "root" user, a.k.a registrar, is + # needed to enroll and invoke new users. + registrar: + enrollId: admin + enrollSecret: adminpw + # [Optional] The optional name of the CA. + caName: ca.org2.example.com \ No newline at end of file diff --git a/test/integration/env.go b/test/integration/env.go index 07ae0bde47..6ec5d01edc 100644 --- a/test/integration/env.go +++ b/test/integration/env.go @@ -15,8 +15,8 @@ import ( ) const ( - configPath = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/config_test.yaml" - entityMangerLocal = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test//fixtures/config/overrides/local_entity_matchers.yaml" + configPath = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/config_test.yaml" + entityMatcherLocal = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test//fixtures/config/overrides/local_entity_matchers.yaml" //LocalOrdererPeersCAsConfig config file to override on local test having only peers, orderers and CA entity entries LocalOrdererPeersCAsConfig = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/config/overrides/local_orderers_peers_ca.yaml" //LocalOrdererPeersConfig config file to override on local test having only peers and orderers entity entries @@ -24,9 +24,11 @@ const ( ) // ConfigBackend contains config backend for integration tests -var ConfigBackend = fetchConfigBackend(configPath, LocalOrdererPeersCAsConfig) +var ConfigBackend = FetchConfigBackend(configPath, LocalOrdererPeersCAsConfig, entityMatcherLocal) -func fetchConfigBackend(configPath string, localOverride string) core.ConfigProvider { +// FetchConfigBackend returns a ConfigProvider that retrieves config data from the given configPath, +// or from the given overrides for local testing +func FetchConfigBackend(configPath string, localOverride, entityMatcherOverride string) core.ConfigProvider { configProvider := config.FromFile(pathvar.Subst(configPath)) args := os.Args[1:] @@ -34,7 +36,7 @@ func fetchConfigBackend(configPath string, localOverride string) core.ConfigProv //If testlocal is enabled, then update config backend to run 'local' test if arg == "testLocal=true" { return func() ([]core.ConfigBackend, error) { - return appendLocalEntityMappingBackend(configProvider, localOverride) + return appendLocalEntityMappingBackend(configProvider, localOverride, entityMatcherOverride) } } } @@ -57,12 +59,12 @@ func IsLocal() bool { // and returns updated config provider func AddLocalEntityMapping(configProvider core.ConfigProvider, configOverridePath string) core.ConfigProvider { return func() ([]core.ConfigBackend, error) { - return appendLocalEntityMappingBackend(configProvider, configOverridePath) + return appendLocalEntityMappingBackend(configProvider, configOverridePath, entityMatcherLocal) } } //appendLocalEntityMappingBackend appends entity matcher backend to given config provider -func appendLocalEntityMappingBackend(configProvider core.ConfigProvider, configOverridePath string) ([]core.ConfigBackend, error) { +func appendLocalEntityMappingBackend(configProvider core.ConfigProvider, configOverridePath, entityMatcherOverridePath string) ([]core.ConfigBackend, error) { //Current backend currentBackends, err := configProvider() if err != nil { @@ -70,7 +72,7 @@ func appendLocalEntityMappingBackend(configProvider core.ConfigProvider, configO } //Entity matcher config backend - configProvider = config.FromFile(pathvar.Subst(entityMangerLocal)) + configProvider = config.FromFile(pathvar.Subst(entityMatcherOverridePath)) matcherBackends, err := configProvider() if err != nil { return nil, err diff --git a/test/integration/orgs/multiple_orgs_minconfig_test.go b/test/integration/orgs/multiple_orgs_minconfig_test.go index 888b92f426..c302999a1f 100644 --- a/test/integration/orgs/multiple_orgs_minconfig_test.go +++ b/test/integration/orgs/multiple_orgs_minconfig_test.go @@ -15,7 +15,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/dynamicdiscovery" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" - "github.com/hyperledger/fabric-sdk-go/pkg/core/config" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/chpvdr" @@ -24,14 +23,18 @@ import ( "github.com/stretchr/testify/require" ) -const bootStrapCC = "btspExampleCC" +const ( + bootStrapCC = "btspExampleCC" + configPath = "../../fixtures/config/config_test_multiorg_bootstrap.yaml" + localOrderersPeersCAConfigPath = "../../fixtures/config/overrides/local_orderers_peers_ca_bootstrap.yaml" + entityMatchersConfigPath = "../../fixtures/config/overrides/local_entity_matchers_bootstrap.yaml" +) //TestOrgsEndToEndWithBootstrapConfigs does the same as TestOrgsEndToEnd with the difference of loading // minimal configs instead of the normal config_test.yaml configs and with the help of discovery service to discover // other peers not in the config (example org1 has 2 peers and only peer0 is defined in the bootstrap configs) func TestOrgsEndToEndWithBootstrapConfigs(t *testing.T) { - configPath := "../../fixtures/config/config_test_multiorg_bootstrap.yaml" - sdk, err := fabsdk.New(config.FromFile(configPath), + sdk, err := fabsdk.New(integration.FetchConfigBackend(configPath, localOrderersPeersCAConfigPath, entityMatchersConfigPath), fabsdk.WithServicePkg(&DynamicDiscoveryProviderFactory{}), ) if err != nil { diff --git a/test/integration/sdk/fabricselection_test.go b/test/integration/sdk/fabricselection_test.go index ffc4b51449..0f93318607 100644 --- a/test/integration/sdk/fabricselection_test.go +++ b/test/integration/sdk/fabricselection_test.go @@ -15,7 +15,6 @@ import ( selectionopts "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/options" "github.com/hyperledger/fabric-sdk-go/pkg/common/options" contextApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context" - "github.com/hyperledger/fabric-sdk-go/pkg/core/config" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/chpvdr" "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl" @@ -37,10 +36,6 @@ const ( peer1Org1 = "peer1.org1.example.com" peer0Org2 = "peer0.org2.example.com" - peer0Org1URL = "peer0.org1.example.com:7051" - peer1Org1URL = "peer1.org1.example.com:7151" - peer0Org2URL = "peer0.org2.example.com:8051" - adminUser = "Admin" org2Name = "Org2" ordererAdminUser = "Admin" @@ -48,8 +43,22 @@ const ( orgChannelID = "orgchannel" ) +var ( + hostToURLMap map[string]string = map[string]string{ + peer0Org1: "peer0.org1.example.com:7051", + peer1Org1: "peer1.org1.example.com:7151", + peer0Org2: "peer0.org2.example.com:8051", + } + + localHostToURLMap map[string]string = map[string]string{ + peer0Org1: "localhost:7051", + peer1Org1: "localhost:7151", + peer0Org2: "localhost:8051", + } +) + func TestFabricSelection(t *testing.T) { - sdk, err := fabsdk.New(config.FromFile("../../fixtures/config/config_test.yaml"), + sdk, err := fabsdk.New(integration.ConfigBackend, fabsdk.WithServicePkg(&fabricSelectionProviderFactory{})) require.NoError(t, err, "Failed to create new SDK") defer sdk.Close() @@ -79,8 +88,8 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID)), expecting( - []string{peer0Org1URL}, - []string{peer1Org1URL}), + []string{getURL(peer0Org1)}, + []string{getURL(peer1Org1)}), ) }) @@ -92,7 +101,7 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID)), expecting( - []string{peer0Org2URL}), + []string{getURL(peer0Org2)}), ) }) @@ -104,9 +113,9 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID)), expecting( - []string{peer0Org1URL}, - []string{peer1Org1URL}, - []string{peer0Org2URL}), + []string{getURL(peer0Org1)}, + []string{getURL(peer1Org1)}, + []string{getURL(peer0Org2)}), ) }) @@ -118,8 +127,8 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID)), expecting( - []string{peer0Org1URL, peer0Org2URL}, - []string{peer1Org1URL, peer0Org2URL}), + []string{getURL(peer0Org1), getURL(peer0Org2)}, + []string{getURL(peer1Org1), getURL(peer0Org2)}), ) // With peer filter @@ -127,9 +136,9 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID)), expecting( - []string{peer1Org1URL, peer0Org2URL}), + []string{getURL(peer1Org1), getURL(peer0Org2)}), selectionopts.WithPeerFilter(func(peer fab.Peer) bool { - return peer.URL() != peer0Org1URL + return peer.URL() != getURL(peer0Org1) }), ) }) @@ -146,8 +155,8 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID1), newCCCall(ccID2)), expecting( - []string{peer0Org1URL, peer0Org2URL}, - []string{peer1Org1URL, peer0Org2URL}), + []string{getURL(peer0Org1), getURL(peer0Org2)}, + []string{getURL(peer1Org1), getURL(peer0Org2)}), ) }) @@ -162,8 +171,8 @@ func TestFabricSelection(t *testing.T) { t, selectionService, chaincodes(newCCCall(ccID, coll1)), expecting( - []string{peer0Org1URL}, - []string{peer1Org1URL}), + []string{getURL(peer0Org1)}, + []string{getURL(peer1Org1)}), ) }) } @@ -391,3 +400,10 @@ func newCollectionConfig(colName, policy string, reqPeerCount, maxPeerCount int3 }, }, nil } + +func getURL(host string) string { + if integration.IsLocal() { + return localHostToURLMap[host] + } + return hostToURLMap[host] +} diff --git a/test/integration/sdk/sdk_dyndiscovery_test.go b/test/integration/sdk/sdk_dyndiscovery_test.go index 5c092b0e63..17e9bc3a88 100644 --- a/test/integration/sdk/sdk_dyndiscovery_test.go +++ b/test/integration/sdk/sdk_dyndiscovery_test.go @@ -12,6 +12,7 @@ import ( "testing" "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/dynamicdiscovery" + "github.com/hyperledger/fabric-sdk-go/test/integration" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/provider/chpvdr" @@ -21,7 +22,6 @@ import ( contextImpl "github.com/hyperledger/fabric-sdk-go/pkg/context" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc" - "github.com/hyperledger/fabric-sdk-go/pkg/core/config" "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk" ) @@ -29,7 +29,7 @@ func TestDynamicDiscovery(t *testing.T) { testSetup := mainTestSetup // Create SDK setup for channel client with dynamic selection - sdk, err := fabsdk.New(config.FromFile("../../fixtures/config/config_test.yaml"), + sdk, err := fabsdk.New(integration.ConfigBackend, fabsdk.WithServicePkg(&dynamicDiscoveryProviderFactory{})) require.NoError(t, err, "Failed to create new SDK") defer sdk.Close() @@ -58,7 +58,7 @@ func TestDynamicLocalDiscovery(t *testing.T) { testSetup := mainTestSetup // Create SDK setup for channel client with dynamic selection - sdk, err := fabsdk.New(config.FromFile("../../fixtures/config/config_test.yaml"), + sdk, err := fabsdk.New(integration.ConfigBackend, fabsdk.WithServicePkg(&dynamicDiscoveryProviderFactory{})) require.NoError(t, err, "Failed to create new SDK") defer sdk.Close()