From fc7ae840f9d60e8fc45ce148b87fc0eb2bc9faca Mon Sep 17 00:00:00 2001 From: Sudesh Shetty Date: Sat, 28 Apr 2018 11:20:52 -0400 Subject: [PATCH] [FAB-9602] Config overrides inplace of custom backends - removed custom backend fallback in mockConfigBackend. instead, config override feature is being used in all unit-test and integration-tests. Change-Id: If088dbe4723eec748da47dc1367d90b83939f2a6 Signed-off-by: Sudesh Shetty --- pkg/client/msp/client_test.go | 10 +- pkg/core/mocks/mockconfigbackend.go | 15 --- pkg/fab/endpointconfig.go | 3 +- pkg/fabsdk/fabsdk_chconfig_test.go | 7 +- pkg/msp/caclient_test.go | 105 ++++++++++-------- pkg/msp/main_test.go | 25 +++-- .../expired_certificate_test.go | 7 +- .../expiredpeer/expired_certificate_test.go | 7 +- test/integration/revoked/revoked_peer_test.go | 11 +- 9 files changed, 102 insertions(+), 88 deletions(-) diff --git a/pkg/client/msp/client_test.go b/pkg/client/msp/client_test.go index 1c46b4720a..2860e52a34 100644 --- a/pkg/client/msp/client_test.go +++ b/pkg/client/msp/client_test.go @@ -178,7 +178,7 @@ func (f *textFixture) setup() *fabsdk.FabricSDK { customBackend := getCustomBackend(backend...) configProvider := func() ([]core.ConfigBackend, error) { - return []core.ConfigBackend{customBackend}, nil + return customBackend, nil } // Instantiate the SDK @@ -233,12 +233,12 @@ func randomUsername() string { return "user" + strconv.Itoa(rand.Intn(500000)) } -func getCustomBackend(backend ...core.ConfigBackend) *mocks.MockConfigBackend { +func getCustomBackend(currentBackends ...core.ConfigBackend) []core.ConfigBackend { backendMap := make(map[string]interface{}) //Custom URLs for ca configs networkConfig := fab.NetworkConfig{} - configLookup := lookup.New(backend...) + configLookup := lookup.New(currentBackends...) configLookup.UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) ca1Config := networkConfig.CertificateAuthorities["ca.org1.example.com"] @@ -250,5 +250,7 @@ func getCustomBackend(backend ...core.ConfigBackend) *mocks.MockConfigBackend { networkConfig.CertificateAuthorities["ca.org2.example.com"] = ca2Config backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities - return &mocks.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend} + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + return append(backends, currentBackends...) + } diff --git a/pkg/core/mocks/mockconfigbackend.go b/pkg/core/mocks/mockconfigbackend.go index 691984d2a4..5abd7a78ac 100644 --- a/pkg/core/mocks/mockconfigbackend.go +++ b/pkg/core/mocks/mockconfigbackend.go @@ -6,29 +6,14 @@ SPDX-License-Identifier: Apache-2.0 package mocks -import ( - "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core" -) - //MockConfigBackend mocks config backend for unit tests type MockConfigBackend struct { //KeyValueMap map to override CustomBackend key-values. KeyValueMap map[string]interface{} - //CustomBackend config backend - CustomBackend []core.ConfigBackend } //Lookup returns or unmarshals value for given key func (b *MockConfigBackend) Lookup(key string) (interface{}, bool) { v, ok := b.KeyValueMap[key] - //if not found in custom map then try with backend - if !ok && b.CustomBackend != nil { - for _, backend := range b.CustomBackend { - val, ok := backend.Lookup(key) - if ok { - return val, true - } - } - } return v, ok } diff --git a/pkg/fab/endpointconfig.go b/pkg/fab/endpointconfig.go index dca2f3b4ea..b8254f9cf1 100644 --- a/pkg/fab/endpointconfig.go +++ b/pkg/fab/endpointconfig.go @@ -296,8 +296,7 @@ func (c *EndpointConfig) NetworkConfig() (*fab.NetworkConfig, error) { return c.networkConfig, nil } -// NetworkPeers returns the network peers configuration -//returns network peers from all the peers from all the +// NetworkPeers returns the network peers configuration, all the peers from all the orgs in config. func (c *EndpointConfig) NetworkPeers() ([]fab.NetworkPeer, error) { netConfig, err := c.NetworkConfig() if err != nil { diff --git a/pkg/fabsdk/fabsdk_chconfig_test.go b/pkg/fabsdk/fabsdk_chconfig_test.go index 208ac442c1..f04054fa92 100644 --- a/pkg/fabsdk/fabsdk_chconfig_test.go +++ b/pkg/fabsdk/fabsdk_chconfig_test.go @@ -82,7 +82,7 @@ func TestNewDefaultTwoValidSDK(t *testing.T) { t.Fatalf("failed to get configbackend for test: %v", err) } configProvider := func() ([]core.ConfigBackend, error) { - return []core.ConfigBackend{customBackend}, nil + return customBackend, nil } sdk2, err := New(configProvider) @@ -147,7 +147,7 @@ func checkClientOrg(configBackend core.ConfigBackend, t *testing.T, orgName stri } } -func getCustomBackend() (*mockCore.MockConfigBackend, error) { +func getCustomBackend() ([]core.ConfigBackend, error) { backend, err := config.FromFile(sdkConfigFile)() if err != nil { return nil, err @@ -167,5 +167,6 @@ func getCustomBackend() (*mockCore.MockConfigBackend, error) { backendMap := make(map[string]interface{}) backendMap["client"] = clientConfig - return &mockCore.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend}, nil + backends := append([]core.ConfigBackend{}, &mockCore.MockConfigBackend{KeyValueMap: backendMap}) + return append(backends, backend...), nil } diff --git a/pkg/msp/caclient_test.go b/pkg/msp/caclient_test.go index 56c62cb71a..78390fccb4 100644 --- a/pkg/msp/caclient_test.go +++ b/pkg/msp/caclient_test.go @@ -14,6 +14,7 @@ import ( "strings" "github.com/golang/mock/gomock" + "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core" fabApi "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp" "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/test/mockcontext" @@ -33,7 +34,7 @@ import ( func TestEnrollAndReenroll(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() orgMSPID := mspIDByOrgName(t, f.endpointConfig, org1) @@ -97,7 +98,7 @@ func reenrollWithAppropriateUser(f textFixture, t *testing.T, enrolledUserData * func TestWrongURL(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() configBackend, err := getInvalidURLBackend() @@ -105,12 +106,12 @@ func TestWrongURL(t *testing.T) { panic(fmt.Sprintf("Failed to get config backend: %v", err)) } - wrongURLIdentityConfig, err := ConfigFromBackend(configBackend) + wrongURLIdentityConfig, err := ConfigFromBackend(configBackend...) if err != nil { panic(fmt.Sprintf("Failed to read config: %v", err)) } - wrongURLEndpointConfig, err := fab.ConfigFromBackend(configBackend) + wrongURLEndpointConfig, err := fab.ConfigFromBackend(configBackend...) if err != nil { panic(fmt.Sprintf("Failed to read config: %v", err)) } @@ -145,7 +146,7 @@ func TestWrongURL(t *testing.T) { func TestNoConfiguredCAs(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() configBackend, err := getNoCAConfigBackend() @@ -153,7 +154,7 @@ func TestNoConfiguredCAs(t *testing.T) { panic(fmt.Sprintf("Failed to get config backend: %v", err)) } - wrongURLEndpointConfig, err := fab.ConfigFromBackend(configBackend) + wrongURLEndpointConfig, err := fab.ConfigFromBackend(configBackend...) if err != nil { panic(fmt.Sprintf("Failed to read config: %v", err)) } @@ -179,7 +180,7 @@ func TestRegister(t *testing.T) { time.Sleep(2 * time.Second) f := textFixture{} - f.setup(nil) + f.setup() defer f.close() // Register with nil request @@ -216,7 +217,7 @@ func TestEmbeddedRegistar(t *testing.T) { } f := textFixture{} - f.setup(embeddedRegistrarBackend) + f.setup(embeddedRegistrarBackend...) defer f.close() // Register with valid request @@ -241,7 +242,7 @@ func TestRegisterNoRegistrar(t *testing.T) { } f := textFixture{} - f.setup(noRegistrarBackend) + f.setup(noRegistrarBackend...) defer f.close() // Register with nil request @@ -271,7 +272,7 @@ func TestRegisterNoRegistrar(t *testing.T) { func TestRevoke(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() // Revoke with nil request @@ -295,7 +296,7 @@ func TestRevoke(t *testing.T) { func TestCAConfigError(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() mockCtrl := gomock.NewController(t) @@ -319,7 +320,7 @@ func TestCAConfigError(t *testing.T) { func TestCAServerCertPathsError(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() mockCtrl := gomock.NewController(t) @@ -345,7 +346,7 @@ func TestCAServerCertPathsError(t *testing.T) { func TestCAClientCertPathError(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() mockCtrl := gomock.NewController(t) @@ -372,7 +373,7 @@ func TestCAClientCertPathError(t *testing.T) { func TestCAClientKeyPathError(t *testing.T) { f := textFixture{} - f.setup(nil) + f.setup() defer f.close() mockCtrl := gomock.NewController(t) @@ -408,25 +409,27 @@ func TestInterfaces(t *testing.T) { } } -func getCustomBackend(configPath string) (*mocks.MockConfigBackend, error) { +func getCustomBackend(configPath string) ([]core.ConfigBackend, error) { - backend, err := config.FromFile(configPath)() + configBackends, err := config.FromFile(configPath)() if err != nil { return nil, err } backendMap := make(map[string]interface{}) - backendMap["client"], _ = backend[0].Lookup("client") - backendMap["certificateAuthorities"], _ = backend[0].Lookup("certificateAuthorities") - backendMap["entityMatchers"], _ = backend[0].Lookup("entityMatchers") - backendMap["peers"], _ = backend[0].Lookup("peers") - backendMap["organizations"], _ = backend[0].Lookup("organizations") - backendMap["orderers"], _ = backend[0].Lookup("orderers") - backendMap["channels"], _ = backend[0].Lookup("channels") - - return &mocks.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend}, nil + backendMap["client"], _ = configBackends[0].Lookup("client") + backendMap["certificateAuthorities"], _ = configBackends[0].Lookup("certificateAuthorities") + backendMap["entityMatchers"], _ = configBackends[0].Lookup("entityMatchers") + backendMap["peers"], _ = configBackends[0].Lookup("peers") + backendMap["organizations"], _ = configBackends[0].Lookup("organizations") + backendMap["orderers"], _ = configBackends[0].Lookup("orderers") + backendMap["channels"], _ = configBackends[0].Lookup("channels") + + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, configBackends...) + return backends, nil } -func getInvalidURLBackend() (*mocks.MockConfigBackend, error) { +func getInvalidURLBackend() ([]core.ConfigBackend, error) { mockConfigBackend, err := getCustomBackend(configPath) if err != nil { @@ -436,7 +439,7 @@ func getInvalidURLBackend() (*mocks.MockConfigBackend, error) { //Create an invalid channel networkConfig := fabApi.NetworkConfig{} //get valid certificate authorities - err = lookup.New(mockConfigBackend).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) + err = lookup.New(mockConfigBackend...).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) if err != nil { return nil, err } @@ -451,12 +454,15 @@ func getInvalidURLBackend() (*mocks.MockConfigBackend, error) { networkConfig.CertificateAuthorities["ca.org2.example.com"] = ca2Config //Override backend with this new CertificateAuthorities config - mockConfigBackend.KeyValueMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backendMap := make(map[string]interface{}) + backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, mockConfigBackend...) - return mockConfigBackend, nil + return backends, nil } -func getNoRegistrarBackend() (*mocks.MockConfigBackend, error) { +func getNoRegistrarBackend() ([]core.ConfigBackend, error) { mockConfigBackend, err := getCustomBackend(configPath) if err != nil { @@ -466,7 +472,7 @@ func getNoRegistrarBackend() (*mocks.MockConfigBackend, error) { //Create an invalid channel networkConfig := fabApi.NetworkConfig{} //get valid certificate authorities - err = lookup.New(mockConfigBackend).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) + err = lookup.New(mockConfigBackend...).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) if err != nil { return nil, err } @@ -481,12 +487,15 @@ func getNoRegistrarBackend() (*mocks.MockConfigBackend, error) { networkConfig.CertificateAuthorities["ca.org2.example.com"] = ca2Config //Override backend with this new CertificateAuthorities config - mockConfigBackend.KeyValueMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backendMap := make(map[string]interface{}) + backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, mockConfigBackend...) - return mockConfigBackend, nil + return backends, nil } -func getNoCAConfigBackend() (*mocks.MockConfigBackend, error) { +func getNoCAConfigBackend() ([]core.ConfigBackend, error) { mockConfigBackend, err := getCustomBackend(configPath) if err != nil { @@ -496,7 +505,7 @@ func getNoCAConfigBackend() (*mocks.MockConfigBackend, error) { //Create an empty network config networkConfig := fabApi.NetworkConfig{} //get valid certificate authorities - err = lookup.New(mockConfigBackend).UnmarshalKey("organizations", &networkConfig.Organizations) + err = lookup.New(mockConfigBackend...).UnmarshalKey("organizations", &networkConfig.Organizations) if err != nil { return nil, err } @@ -506,15 +515,19 @@ func getNoCAConfigBackend() (*mocks.MockConfigBackend, error) { org1.CertificateAuthorities = []string{} networkConfig.Organizations["org1"] = org1 + backendMap := make(map[string]interface{}) //Override backend with organization config having empty CertificateAuthorities - mockConfigBackend.KeyValueMap["organizations"] = networkConfig.Organizations + backendMap["organizations"] = networkConfig.Organizations //Override backend with this nil empty CertificateAuthorities config - mockConfigBackend.KeyValueMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities - return mockConfigBackend, nil + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, mockConfigBackend...) + + return backends, nil } -func getEmbeddedRegistrarConfigBackend() (*mocks.MockConfigBackend, error) { +func getEmbeddedRegistrarConfigBackend() ([]core.ConfigBackend, error) { mockConfigBackend, err := getCustomBackend(configPath) if err != nil { @@ -526,11 +539,11 @@ func getEmbeddedRegistrarConfigBackend() (*mocks.MockConfigBackend, error) { //Create an empty network config networkConfig := fabApi.NetworkConfig{} //get valid certificate authorities - err = lookup.New(mockConfigBackend).UnmarshalKey("organizations", &networkConfig.Organizations) + err = lookup.New(mockConfigBackend...).UnmarshalKey("organizations", &networkConfig.Organizations) if err != nil { return nil, err } - err = lookup.New(mockConfigBackend).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) + err = lookup.New(mockConfigBackend...).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) if err != nil { return nil, err } @@ -572,10 +585,14 @@ XdsmTcdRvJ3TS/6HCA== networkConfig.CertificateAuthorities["ca.org1.example.com"] = ca1Config networkConfig.CertificateAuthorities["ca.org2.example.com"] = ca2Config + backendMap := make(map[string]interface{}) //Override backend with updated organization config - mockConfigBackend.KeyValueMap["organizations"] = networkConfig.Organizations + backendMap["organizations"] = networkConfig.Organizations //Override backend with updated certificate authorities config - mockConfigBackend.KeyValueMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, mockConfigBackend...) - return mockConfigBackend, nil + return backends, nil } diff --git a/pkg/msp/main_test.go b/pkg/msp/main_test.go index 9eec435481..ed2424bb35 100644 --- a/pkg/msp/main_test.go +++ b/pkg/msp/main_test.go @@ -49,9 +49,9 @@ type textFixture struct { var caServer = &mockmsp.MockFabricCAServer{} -func (f *textFixture) setup(configBackend *mocks.MockConfigBackend) { //nolint +func (f *textFixture) setup(configBackend ...core.ConfigBackend) { //nolint - if configBackend == nil { + if len(configBackend) == 0 { backend, err := getCustomBackend(configPath) if err != nil { panic(err) @@ -70,16 +70,16 @@ func (f *textFixture) setup(configBackend *mocks.MockConfigBackend) { //nolint caServerURL = "http://" + lis.Addr().String() } - updateCAServerURL(caServerURL, configBackend) + configBackend = updateCAServerURL(caServerURL, configBackend) - f.cryptSuiteConfig = cryptosuite.ConfigFromBackend(configBackend) + f.cryptSuiteConfig = cryptosuite.ConfigFromBackend(configBackend...) - f.endpointConfig, err = fabImpl.ConfigFromBackend(configBackend) + f.endpointConfig, err = fabImpl.ConfigFromBackend(configBackend...) if err != nil { panic(fmt.Sprintf("Failed to read config : %v", err)) } - f.identityConfig, err = ConfigFromBackend(configBackend) + f.identityConfig, err = ConfigFromBackend(configBackend...) if err != nil { panic(fmt.Sprintf("Failed to read config : %v", err)) } @@ -206,11 +206,11 @@ func (p *identityManagerProvider) IdentityManager(orgName string) (msp.IdentityM return im, true } -func updateCAServerURL(caServerURL string, backend *mocks.MockConfigBackend) { +func updateCAServerURL(caServerURL string, existingBackends []core.ConfigBackend) []core.ConfigBackend { //get existing certificateAuthorities networkConfig := fab.NetworkConfig{} - lookup.New(backend).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) + lookup.New(existingBackends...).UnmarshalKey("certificateAuthorities", &networkConfig.CertificateAuthorities) //update URLs ca1Config := networkConfig.CertificateAuthorities["ca.org1.example.com"] @@ -223,5 +223,12 @@ func updateCAServerURL(caServerURL string, backend *mocks.MockConfigBackend) { networkConfig.CertificateAuthorities[".ca.org2.example.com"] = ca2Config //update backend - backend.KeyValueMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + backendMap := make(map[string]interface{}) + //Override backend with updated certificate authorities config + backendMap["certificateAuthorities"] = networkConfig.CertificateAuthorities + + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + backends = append(backends, existingBackends...) + + return backends } diff --git a/test/integration/expiredorderer/expired_certificate_test.go b/test/integration/expiredorderer/expired_certificate_test.go index f7f744ae08..6f3375bc85 100644 --- a/test/integration/expiredorderer/expired_certificate_test.go +++ b/test/integration/expiredorderer/expired_certificate_test.go @@ -96,7 +96,7 @@ func TestExpiredCert(t *testing.T) { func getConfigBackend(t *testing.T) core.ConfigProvider { return func() ([]core.ConfigBackend, error) { - backend, err := config.FromFile(configPath)() + configBackends, err := config.FromFile(configPath)() if err != nil { t.Fatalf("failed to read config backend from file, %v", err) } @@ -104,7 +104,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig := fab.NetworkConfig{} //get valid orderers config - err = lookup.New(backend...).UnmarshalKey("orderers", &networkConfig.Orderers) + err = lookup.New(configBackends...).UnmarshalKey("orderers", &networkConfig.Orderers) if err != nil { t.Fatalf("failed to unmarshal peer network config, %v", err) } @@ -114,6 +114,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig.Orderers["orderer.example.com"] = orderer1 backendMap["orderers"] = networkConfig.Orderers - return []core.ConfigBackend{&mocks.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend}}, nil + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + return append(backends, configBackends...), nil } } diff --git a/test/integration/expiredpeer/expired_certificate_test.go b/test/integration/expiredpeer/expired_certificate_test.go index f5db33ded2..aedb4b6ef4 100644 --- a/test/integration/expiredpeer/expired_certificate_test.go +++ b/test/integration/expiredpeer/expired_certificate_test.go @@ -98,7 +98,7 @@ func TestExpiredPeersCert(t *testing.T) { func getConfigBackend(t *testing.T) core.ConfigProvider { return func() ([]core.ConfigBackend, error) { - backend, err := config.FromFile(configPath)() + configBackends, err := config.FromFile(configPath)() if err != nil { t.Fatalf("failed to read config backend from file, %v", err) } @@ -106,7 +106,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig := fab.NetworkConfig{} //get valid peer config - err = lookup.New(backend...).UnmarshalKey("peers", &networkConfig.Peers) + err = lookup.New(configBackends...).UnmarshalKey("peers", &networkConfig.Peers) if err != nil { t.Fatalf("failed to unmarshal peer network config, %v", err) } @@ -116,6 +116,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig.Peers["peer0.org1.example.com"] = peer1 backendMap["peers"] = networkConfig.Peers - return []core.ConfigBackend{&mocks.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend}}, nil + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + return append(backends, configBackends...), nil } } diff --git a/test/integration/revoked/revoked_peer_test.go b/test/integration/revoked/revoked_peer_test.go index 54151dda14..10730cd779 100644 --- a/test/integration/revoked/revoked_peer_test.go +++ b/test/integration/revoked/revoked_peer_test.go @@ -203,7 +203,7 @@ func loadOrgPeers(t *testing.T, ctxProvider contextAPI.ClientProvider) { func getConfigBackend(t *testing.T) core.ConfigProvider { return func() ([]core.ConfigBackend, error) { - backend, err := config.FromFile(configPath)() + configBackends, err := config.FromFile(configPath)() if err != nil { t.Fatalf("failed to read config backend from file, %v", err) } @@ -211,7 +211,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig := fab.NetworkConfig{} //get valid peer config - err = lookup.New(backend...).UnmarshalKey("peers", &networkConfig.Peers) + err = lookup.New(configBackends...).UnmarshalKey("peers", &networkConfig.Peers) if err != nil { t.Fatalf("failed to unmarshal peer network config, %v", err) } @@ -229,7 +229,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig.Peers["peer1.org2.example.com"] = peer2 //get valid org2 - err = lookup.New(backend...).UnmarshalKey("organizations", &networkConfig.Organizations) + err = lookup.New(configBackends...).UnmarshalKey("organizations", &networkConfig.Organizations) if err != nil { t.Fatalf("failed to unmarshal organizations network config, %v", err) } @@ -241,7 +241,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { networkConfig.Organizations["org2"] = org2 //custom channel - err = lookup.New(backend...).UnmarshalKey("channels", &networkConfig.Channels) + err = lookup.New(configBackends...).UnmarshalKey("channels", &networkConfig.Channels) if err != nil { t.Fatalf("failed to unmarshal entityMatchers network config, %v", err) } @@ -261,6 +261,7 @@ func getConfigBackend(t *testing.T) core.ConfigProvider { backendMap["organizations"] = networkConfig.Organizations backendMap["channels"] = networkConfig.Channels - return []core.ConfigBackend{&mocks.MockConfigBackend{KeyValueMap: backendMap, CustomBackend: backend}}, nil + backends := append([]core.ConfigBackend{}, &mocks.MockConfigBackend{KeyValueMap: backendMap}) + return append(backends, configBackends...), nil } }