Skip to content

Commit

Permalink
[FAB-9238] local int tests to use configbackend
Browse files Browse the repository at this point in the history
-instead of using different config files for local
integration tests, customized backend with updated
entity matchers is used.

Change-Id: I0816123e0c8287d16818f45872ccaa21dcf6abc9
Signed-off-by: Sudesh Shetty <[email protected]>
  • Loading branch information
sudeshrshetty committed Apr 11, 2018
1 parent b4f68e3 commit f332aba
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 667 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ FIXTURE_DOCKER_REMOVE_FORCE ?= false
# Options for exercising unit tests (overridable)
FABRIC_SDK_DEPRECATED_UNITTEST ?= false

#config files
INT_TESTS_LOCAL_CONFIG_FILE := config_test_local.yaml

# Code levels to exercise integration/e2e tests against (overridable)
FABRIC_STABLE_INTTEST ?= true
FABRIC_STABLE_PKCS11_INTTEST ?= false
Expand Down Expand Up @@ -333,7 +330,7 @@ endif

.PHONY: integration-tests-local
integration-tests-local: temp-clean depend populate
FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_CODELEVEL_TAG) CONFIG_FILE=$(INT_TESTS_LOCAL_CONFIG_FILE) $(TEST_SCRIPTS_PATH)/integration.sh
FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_CODELEVEL_TAG) TEST_LOCAL=true $(TEST_SCRIPTS_PATH)/integration.sh

.PHONY: dockerenv-prev-up
dockerenv-prev-up: clean
Expand Down
423 changes: 0 additions & 423 deletions test/fixtures/config/config_test_local.yaml

This file was deleted.

191 changes: 0 additions & 191 deletions test/fixtures/config/config_test_no_orderer_local.yaml

This file was deleted.

99 changes: 99 additions & 0 deletions test/fixtures/config/entity_matchers_local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#
# 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.
#


# EntityMatchers enable substitution of network hostnames with static configurations
# so that properties can be mapped. Regex can be used for this purpose
# UrlSubstitutionExp can be empty which means the same network hostname will be used
# UrlSubstitutionExp can be given same as mapped peer url, so that mapped peer url can be used
# UrlSubstitutionExp can have golang regex matchers like $1.local.example.$2:$3 for pattern
# like peer0.org1.example.com:1234 which converts peer0.org1.example.com to peer0.org1.local.example.com:1234
# EventUrlSubstitutionExp and sslTargetOverrideUrlSubstitutionExp follow in the same lines as
# SubstitutionExp for the fields eventUrl and gprcOptions.ssl-target-name-override respectively
# In any case mappedHost's config will be used, so mapped host cannot be empty, if entityMatchers are used
entityMatchers:
peer:
- pattern: (\w+).org1.example.(\w+)
urlSubstitutionExp: localhost:7051
eventUrlSubstitutionExp: localhost:7053
sslTargetOverrideUrlSubstitutionExp: peer0.org1.example.com
mappedHost: local.peer0.org1.example.com

- pattern: (\w+).org2.example.(\w+)
urlSubstitutionExp: localhost:8051
eventUrlSubstitutionExp: localhost:8053
sslTargetOverrideUrlSubstitutionExp: peer0.org2.example.com
mappedHost: local.peer0.org2.example.com

- pattern: (\w+).example.(\w+)
urlSubstitutionExp: localhost:7051
eventUrlSubstitutionExp: localhost:7053
sslTargetOverrideUrlSubstitutionExp: localhost
mappedHost: local.peer0.org1.example.com

- pattern: (\w+).example2.(\w+):(\d+)
urlSubstitutionExp: localhost:7051
eventUrlSubstitutionExp: localhost:7053
sslTargetOverrideUrlSubstitutionExp: localhost
mappedHost: local.peer0.org2.example.com

- pattern: (\w+).example3.(\w+)
urlSubstitutionExp:
eventUrlSubstitutionExp:
sslTargetOverrideUrlSubstitutionExp:
mappedHost: local.peer0.org1.example.com

- pattern: (\w+).example4.(\w+):(\d+)
urlSubstitutionExp: $1.org1.example.$2:$3
eventUrlSubstitutionExp: $1.org1.example.$2:7053
sslTargetOverrideUrlSubstitutionExp: $1.org1.example.$2
mappedHost: local.peer0.org1.example.com

- pattern: (\w+).example2.com:(\d+)
urlSubstitutionExp: peer0.org2.example.com:7051
eventUrlSubstitutionExp:
sslTargetOverrideUrlSubstitutionExp:
mappedHost: local.peer0.org2.example.com

orderer:
- pattern: (\w+).example2.(\w+)
urlSubstitutionExp: localhost:7050
sslTargetOverrideUrlSubstitutionExp: localhost
mappedHost: local.orderer.example.com

- 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

- pattern: (\w+).example3.(\w+)
urlSubstitutionExp:
sslTargetOverrideUrlSubstitutionExp:
mappedHost: local.orderer.example.com

- pattern: (\w+).example4.(\w+):(\d+)
urlSubstitutionExp: $1.example.$2:$3
sslTargetOverrideUrlSubstitutionExp: $1.example.$2
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
8 changes: 1 addition & 7 deletions test/integration/base_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fab"
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
Expand Down Expand Up @@ -79,7 +78,7 @@ func (setup *BaseSetupImpl) Initialize(sdk *fabsdk.FabricSDK) error {
configBackend, err := sdk.Config()
if err != nil {
//For some tests SDK may not have backend set, try with config file if backend is missing
configBackend, err = config.FromFile(setup.ConfigFile)()
configBackend, err = ConfigBackend()
if err != nil {
return errors.Wrapf(err, "failed to get config backend from config: %v", err)
}
Expand Down Expand Up @@ -125,11 +124,6 @@ func getOrgTargets(configBackend core.ConfigBackend, org string) ([]string, erro
return targets, nil
}

// InitConfig ...
func (setup *BaseSetupImpl) InitConfig() core.ConfigProvider {
return config.FromFile(setup.ConfigFile)
}

// GetDeployPath ..
func GetDeployPath() string {
pwd, _ := os.Getwd()
Expand Down
8 changes: 7 additions & 1 deletion test/integration/e2e/end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@ const (
orgAdmin = "Admin"
ordererOrgName = "ordererorg"
ccID = "e2eExampleCC"
configPath = "../../fixtures/config/config_test.yaml"
)

func runWithConfigFixture(t *testing.T) {
Run(t, config.FromFile("../"+integration.ConfigTestFile))
Run(t, config.FromFile(configPath))
}

// Run enables testing an end-to-end scenario against the supplied SDK options
func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option) {

if integration.IsLocal() {
//If it is a local test then add entity mapping to config backend to parse URLs
configOpt = integration.AddLocalEntityMapping(configOpt)
}

sdk, err := fabsdk.New(configOpt, sdkOpts...)
if err != nil {
t.Fatalf("Failed to create new SDK: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions test/integration/e2e/no_orderer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"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/test/integration"
)

func runWithNoOrdererConfigFixture(t *testing.T) {
runWithNoOrdererConfig(t, config.FromFile("../"+integration.ConfigChBlockTestFile))
runWithNoOrdererConfig(t, integration.ConfigNoOrdererBackend)
}

// RunWithNoOrdererConfig enables chclient scenarios using config and sdk options provided
Expand Down
Loading

0 comments on commit f332aba

Please sign in to comment.