From f048f161d5ff6be28dffee96a344ae732df5a7e4 Mon Sep 17 00:00:00 2001 From: Sandra Vrtikapa Date: Wed, 4 Oct 2017 14:44:40 -0400 Subject: [PATCH] [FAB-6423] Go SDK config reused issue Change-Id: I89bc8a91532e8b1ebd4bb79bcf82c27bc405adeb Signed-off-by: Sandra Vrtikapa --- def/fabapi/fabapi_test.go | 85 ++++++++++++++- def/fabapi/testdata/test.yaml | 129 +++++++++++++++++++++++ pkg/config/config.go | 75 ++++++------- pkg/config/config_test.go | 82 ++++++-------- pkg/fabric-ca-client/mocks/mockconfig.go | 7 -- pkg/fabric-client/mocks/mockconfig.go | 8 -- test/fixtures/config/config_test.yaml | 1 - 7 files changed, 279 insertions(+), 108 deletions(-) create mode 100755 def/fabapi/testdata/test.yaml diff --git a/def/fabapi/fabapi_test.go b/def/fabapi/fabapi_test.go index 1116dfb86c..d4fa64a275 100644 --- a/def/fabapi/fabapi_test.go +++ b/def/fabapi/fabapi_test.go @@ -15,20 +15,103 @@ import ( func TestNewDefaultSDK(t *testing.T) { setup := Options{ - ConfigFile: "../../test/fixtures/config/config_test.yaml", + ConfigFile: "../../test/fixtures/config/invalid.yaml", StateStoreOpts: opt.StateStoreOpts{ Path: "/tmp/state", }, } + // Test new SDK with invalid config file + _, err := NewSDK(setup) + if err == nil { + t.Fatalf("Should have failed for invalid config file") + } + + // Test New SDK with valid config file + setup.ConfigFile = "../../test/fixtures/config/config_test.yaml" sdk, err := NewSDK(setup) if err != nil { t.Fatalf("Error initializing SDK: %s", err) } + // Default channel client (uses organisation from client configuration) _, err = sdk.NewChannelClient("mychannel", "User1") if err != nil { t.Fatalf("Failed to create new channel client: %s", err) } + // Test configuration failure for channel client (mychannel does't have event source configured for Org2) + _, err = sdk.NewChannelClientWithOpts("mychannel", "User1", &ChannelClientOpts{OrgName: "Org2"}) + if err == nil { + t.Fatalf("Should have failed to create channel client since event source not configured for Org2") + } + + // Test new channel client with options + _, err = sdk.NewChannelClientWithOpts("orgchannel", "User1", &ChannelClientOpts{OrgName: "Org2"}) + if err != nil { + t.Fatalf("Failed to create new channel client: %s", err) + } + +} + +func TestNewDefaultTwoValidSDK(t *testing.T) { + setup := Options{ + ConfigFile: "../../test/fixtures/config/config_test.yaml", + StateStoreOpts: opt.StateStoreOpts{ + Path: "/tmp/state", + }, + } + + sdk1, err := NewSDK(setup) + if err != nil { + t.Fatalf("Error initializing SDK: %s", err) + } + + setup.ConfigFile = "./testdata/test.yaml" + sdk2, err := NewSDK(setup) + if err != nil { + t.Fatalf("Error initializing SDK: %s", err) + } + + // Default sdk with two channels + client1, err := sdk1.configProvider.Client() + if err != nil { + t.Fatalf("Error getting client from config: %s", err) + } + + if client1.Organization != "Org1" { + t.Fatalf("Unexpected org in config: %s", client1.Organization) + } + + client2, err := sdk2.configProvider.Client() + if err != nil { + t.Fatalf("Error getting client from config: %s", err) + } + + if client2.Organization != "Org2" { + t.Fatalf("Unexpected org in config: %s", client1.Organization) + } + + // Test SDK1 channel clients ('mychannel', 'orgchannel') + _, err = sdk1.NewChannelClient("mychannel", "User1") + if err != nil { + t.Fatalf("Failed to create new channel client: %s", err) + } + + _, err = sdk1.NewChannelClient("orgchannel", "User1") + if err != nil { + t.Fatalf("Failed to create new channel client: %s", err) + } + + // SDK 2 doesn't have 'mychannel' configured + _, err = sdk2.NewChannelClient("mychannel", "User1") + if err == nil { + t.Fatalf("Should have failed to create channel that is not configured") + } + + // SDK 2 has 'orgchannel' configured + _, err = sdk2.NewChannelClient("orgchannel", "User1") + if err != nil { + t.Fatalf("Failed to create new 'orgchannel' channel client: %s", err) + } } diff --git a/def/fabapi/testdata/test.yaml b/def/fabapi/testdata/test.yaml new file mode 100755 index 0000000000..1e4d4f9edd --- /dev/null +++ b/def/fabapi/testdata/test.yaml @@ -0,0 +1,129 @@ +# +# Copyright SecureKey Technologies Inc. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +name: "global-trade-network" + +x-type: "hlfv1" +x-loggingLevel: info + +description: "The network to be in if you want to stay in the global trade business" +version: 1.0.0 + +client: + organization: Org2 + + logging: + level: info + +# Global configuration for peer, event service and orderer timeouts + peer: + timeout: + connection: 3s + queryResponse: 20s + executeTxResponse: 30s + eventService: + timeout: + connection: 3s + registrationResponse: 3s + orderer: + timeout: + connection: 3s + response: 5s + + cryptoconfig: + path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config + + credentialStore: + path: "/tmp/hfc-kvs" + + cryptoStore: + # Specific to the underlying KeyValueStore that backs the crypto key store. + path: /tmp/msp + + # BCCSP config for the client. Used by GO SDK. + BCCSP: + security: + enabled: true + default: + provider: "SW" + hashAlgorithm: "SHA2" + softVerify: true + ephemeral: false + level: 256 + +channels: + + orgchannel: + + orderers: + - orderer.example.com + + peers: + peer0.org2.example.com: + endorsingPeer: true + chaincodeQuery: true + ledgerQuery: true + eventSource: true + +organizations: + + Org2: + mspid: Org2MSP + + # Needed to load users crypto keys and certs for this org (absolute path or relative to global crypto path, DEV mode) + cryptoPath: peerOrganizations/org2.example.com/users/{userName}@org2.example.com/msp + + peers: + - peer0.org2.example.com + + certificateAuthorities: + - ca-org2 + + ordererorg: + 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 + + +orderers: + orderer.example.com: + url: grpcs://orderer.example.com:7050 + + grpcOptions: + ssl-target-name-override: orderer.example.com + grpc-max-send-message-length: 15 + + tlsCACerts: + path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem + +peers: + peer0.org2.example.com: + url: grpcs://peer0.org2.example.com:7051 + eventUrl: grpcs://peer0.org2.example.com:7053 + grpcOptions: + ssl-target-name-override: peer0.org2.example.com + tlsCACerts: + path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/channel/crypto-config/peerOrganizations/org2.example.com/tlsca/tlsca.org2.example.com-cert.pem + +certificateAuthorities: + ca-org2: + url: https://ca_peerOrg2:7054 + + httpOptions: + verify: true + + tlsCACerts: + path: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/ca_root.pem + client: + keyfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client-key.pem + certfile: $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/tls/fabricca/certs/client/client_fabric_client.pem + + registrar: + enrollId: admin + enrollSecret: adminpw + + caName: ca-org2 diff --git a/pkg/config/config.go b/pkg/config/config.go index 18fb12ded1..1ba80f7fdf 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -29,7 +29,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/pkcs11" ) -var myViper = viper.New() var logger = logging.NewLogger("fabric_sdk_go") const ( @@ -42,22 +41,24 @@ type Config struct { tlsCertPool *x509.CertPool networkConfig *apiconfig.NetworkConfig networkConfigCached bool + configViper *viper.Viper } // InitConfig ... // initConfig reads in config file -func InitConfig(configFile string) (apiconfig.Config, error) { +func InitConfig(configFile string) (*Config, error) { return InitConfigWithCmdRoot(configFile, cmdRoot) } // InitConfigWithCmdRoot reads in a config file and allows the // environment variable prefixed to be specified func InitConfigWithCmdRoot(configFile string, cmdRootPrefix string) (*Config, error) { + myViper := viper.New() myViper.SetEnvPrefix(cmdRootPrefix) myViper.AutomaticEnv() replacer := strings.NewReplacer(".", "_") myViper.SetEnvKeyReplacer(replacer) - err := loadDefaultConfig() + err := loadDefaultConfig(myViper) if err != nil { return nil, err } @@ -87,11 +88,11 @@ func InitConfigWithCmdRoot(configFile string, cmdRootPrefix string) (*Config, er logging.SetLevel(logging.Level(logLevel), "fabric_sdk_go") logger.Infof("fabric_sdk_go Logging level is finally set to: %s", logging.GetLevel("fabric_sdk_go")) - return &Config{tlsCertPool: x509.NewCertPool()}, nil + return &Config{tlsCertPool: x509.NewCertPool(), configViper: myViper}, nil } // load Default confid -func loadDefaultConfig() error { +func loadDefaultConfig(myViper *viper.Viper) error { // get Environment Default Config Path defaultPath := os.Getenv("FABRIC_SDK_CONFIG_PATH") if defaultPath != "" { // if set, use it to load default config @@ -217,19 +218,19 @@ func (c *Config) TimeoutOrDefault(conn apiconfig.TimeoutType) time.Duration { var timeout time.Duration switch conn { case apiconfig.Endorser: - timeout = myViper.GetDuration("client.peer.timeout.connection") + timeout = c.configViper.GetDuration("client.peer.timeout.connection") case apiconfig.Query: - timeout = myViper.GetDuration("client.peer.timeout.queryResponse") + timeout = c.configViper.GetDuration("client.peer.timeout.queryResponse") case apiconfig.ExecuteTx: - timeout = myViper.GetDuration("client.peer.timeout.executeTxResponse") + timeout = c.configViper.GetDuration("client.peer.timeout.executeTxResponse") case apiconfig.EventHub: - timeout = myViper.GetDuration("client.eventService.timeout.connection") + timeout = c.configViper.GetDuration("client.eventService.timeout.connection") case apiconfig.EventReg: - timeout = myViper.GetDuration("client.eventService.timeout.registrationResponse") + timeout = c.configViper.GetDuration("client.eventService.timeout.registrationResponse") case apiconfig.OrdererConnection: - timeout = myViper.GetDuration("client.orderer.timeout.connection") + timeout = c.configViper.GetDuration("client.orderer.timeout.connection") case apiconfig.OrdererResponse: - timeout = myViper.GetDuration("client.orderer.timeout.response") + timeout = c.configViper.GetDuration("client.orderer.timeout.response") } if timeout == 0 { @@ -254,45 +255,39 @@ func (c *Config) MspID(org string) (string, error) { return mspID, nil } -// FabricClientViper returns the internal viper instance used by the -// SDK to read configuration options -func FabricClientViper() *viper.Viper { - return myViper -} - func (c *Config) cacheNetworkConfiguration() error { c.networkConfig = new(apiconfig.NetworkConfig) - c.networkConfig.Name = myViper.GetString("name") - c.networkConfig.Xtype = myViper.GetString("x-type") - c.networkConfig.Description = myViper.GetString("description") - c.networkConfig.Version = myViper.GetString("version") + c.networkConfig.Name = c.configViper.GetString("name") + c.networkConfig.Xtype = c.configViper.GetString("x-type") + c.networkConfig.Description = c.configViper.GetString("description") + c.networkConfig.Version = c.configViper.GetString("version") - err := myViper.UnmarshalKey("client", &c.networkConfig.Client) + err := c.configViper.UnmarshalKey("client", &c.networkConfig.Client) logger.Debugf("Client is: %+v", c.networkConfig.Client) if err != nil { return err } - err = myViper.UnmarshalKey("channels", &c.networkConfig.Channels) + err = c.configViper.UnmarshalKey("channels", &c.networkConfig.Channels) logger.Debugf("channels are: %+v", c.networkConfig.Channels) if err != nil { return err } - err = myViper.UnmarshalKey("organizations", &c.networkConfig.Organizations) + err = c.configViper.UnmarshalKey("organizations", &c.networkConfig.Organizations) logger.Debugf("organizations are: %+v", c.networkConfig.Organizations) if err != nil { return err } - err = myViper.UnmarshalKey("orderers", &c.networkConfig.Orderers) + err = c.configViper.UnmarshalKey("orderers", &c.networkConfig.Orderers) logger.Debugf("orderers are: %+v", c.networkConfig.Orderers) if err != nil { return err } - err = myViper.UnmarshalKey("peers", &c.networkConfig.Peers) + err = c.configViper.UnmarshalKey("peers", &c.networkConfig.Peers) logger.Debugf("peers are: %+v", c.networkConfig.Peers) if err != nil { return err } - err = myViper.UnmarshalKey("certificateAuthorities", &c.networkConfig.CertificateAuthorities) + err = c.configViper.UnmarshalKey("certificateAuthorities", &c.networkConfig.CertificateAuthorities) logger.Debugf("certificateAuthorities are: %+v", c.networkConfig.CertificateAuthorities) if err != nil { return err @@ -539,37 +534,37 @@ func (c *Config) TLSCACertPool(tlsCertificate string) (*x509.CertPool, error) { // IsSecurityEnabled ... func (c *Config) IsSecurityEnabled() bool { - return myViper.GetBool("client.BCCSP.security.enabled") + return c.configViper.GetBool("client.BCCSP.security.enabled") } // SecurityAlgorithm ... func (c *Config) SecurityAlgorithm() string { - return myViper.GetString("client.BCCSP.security.hashAlgorithm") + return c.configViper.GetString("client.BCCSP.security.hashAlgorithm") } // SecurityLevel ... func (c *Config) SecurityLevel() int { - return myViper.GetInt("client.BCCSP.security.level") + return c.configViper.GetInt("client.BCCSP.security.level") } //SecurityProvider provider SW or PKCS11 func (c *Config) SecurityProvider() string { - return myViper.GetString("client.BCCSP.security.default.provider") + return c.configViper.GetString("client.BCCSP.security.default.provider") } //Ephemeral flag func (c *Config) Ephemeral() bool { - return myViper.GetBool("client.BCCSP.security.ephemeral") + return c.configViper.GetBool("client.BCCSP.security.ephemeral") } //SoftVerify flag func (c *Config) SoftVerify() bool { - return myViper.GetBool("client.BCCSP.security.softVerify") + return c.configViper.GetBool("client.BCCSP.security.softVerify") } //SecurityProviderLibPath will be set only if provider is PKCS11 func (c *Config) SecurityProviderLibPath() string { - configuredLibs := myViper.GetString("client.BCCSP.security.library") + configuredLibs := c.configViper.GetString("client.BCCSP.security.library") libPaths := strings.Split(configuredLibs, ",") logger.Debug("Configured BCCSP Lib Paths %v", libPaths) var lib string @@ -589,17 +584,17 @@ func (c *Config) SecurityProviderLibPath() string { //SecurityProviderPin will be set only if provider is PKCS11 func (c *Config) SecurityProviderPin() string { - return myViper.GetString("client.BCCSP.security.pin") + return c.configViper.GetString("client.BCCSP.security.pin") } //SecurityProviderLabel will be set only if provider is PKCS11 func (c *Config) SecurityProviderLabel() string { - return myViper.GetString("client.BCCSP.security.label") + return c.configViper.GetString("client.BCCSP.security.label") } // KeyStorePath returns the keystore path used by BCCSP func (c *Config) KeyStorePath() string { - keystorePath := strings.Replace(myViper.GetString("client.credentialStore.cryptoStore.path"), + keystorePath := strings.Replace(c.configViper.GetString("client.credentialStore.cryptoStore.path"), "$GOPATH", os.Getenv("GOPATH"), -1) return path.Join(keystorePath, "keystore") } @@ -608,13 +603,13 @@ func (c *Config) KeyStorePath() string { // 'keystore' directory added. This is done because the fabric-ca-client // adds this to the path func (c *Config) CAKeyStorePath() string { - return strings.Replace(myViper.GetString("client.credentialStore.cryptoStore.path"), + return strings.Replace(c.configViper.GetString("client.credentialStore.cryptoStore.path"), "$GOPATH", os.Getenv("GOPATH"), -1) } // CryptoConfigPath ... func (c *Config) CryptoConfigPath() string { - return strings.Replace(myViper.GetString("client.cryptoconfig.path"), + return strings.Replace(c.configViper.GetString("client.cryptoconfig.path"), "$GOPATH", os.Getenv("GOPATH"), -1) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 53a7d73380..cd0790bb23 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -20,7 +20,7 @@ import ( "github.com/spf13/viper" ) -var configImpl api.Config +var configImpl *Config var org0 = "org0" var org1 = "Org1" @@ -74,7 +74,7 @@ func TestCAConfig(t *testing.T) { } //Test Crypto config path - crossCheckWithViperConfig(myViper.GetString("client.cryptoconfig.path"), configImpl.CryptoConfigPath(), "Incorrect crypto config path", t) + crossCheckWithViperConfig(configImpl.configViper.GetString("client.cryptoconfig.path"), configImpl.CryptoConfigPath(), "Incorrect crypto config path", t) //Testing CA Client File Location certfile, err := configImpl.CAClientCertFile(org1) @@ -179,18 +179,11 @@ func TestCAConfigFailsByNetworkConfig(t *testing.T) { //Tamper 'client.network' value and use a new config to avoid conflicting with other tests sampleConfig, err := InitConfig("../../test/fixtures/config/config_test.yaml") - clientNetworkName := myViper.Get("client") - peers := myViper.Get("peers") - organizations := myViper.Get("organizations") - orderers := myViper.Get("orderers") - channels := myViper.Get("channels") - bccspSwProvider := myViper.GetString("client.BCCSP.security.default.provider") - myViper.Set("client", "INVALID") - myViper.Set("peers", "INVALID") - myViper.Set("organizations", "INVALID") - myViper.Set("orderers", "INVALID") - myViper.Set("channels", "INVALID") - //... + sampleConfig.configViper.Set("client", "INVALID") + sampleConfig.configViper.Set("peers", "INVALID") + sampleConfig.configViper.Set("organizations", "INVALID") + sampleConfig.configViper.Set("orderers", "INVALID") + sampleConfig.configViper.Set("channels", "INVALID") _, err = sampleConfig.NetworkConfig() if err == nil { @@ -252,7 +245,7 @@ func TestCAConfigFailsByNetworkConfig(t *testing.T) { } // Testing empty BCCSP Software provider - myViper.Set("client.BCCSP.security.default.provider", "") + sampleConfig.configViper.Set("client.BCCSP.security.default.provider", "") func() { defer func() { if r := recover(); r == nil { @@ -263,19 +256,11 @@ func TestCAConfigFailsByNetworkConfig(t *testing.T) { }() // test empty network objects - myViper.Set("organizations", nil) + sampleConfig.configViper.Set("organizations", nil) _, err = sampleConfig.NetworkConfig() if err == nil { t.Fatalf("Organizations were empty, it should return an error") } - - //Set it back to valid one, otherwise other tests may fail - myViper.Set("client.network", clientNetworkName) - myViper.Set("peers", peers) - myViper.Set("organizations", organizations) - myViper.Set("orderers", orderers) - myViper.Set("channels", channels) - myViper.Set("client.BCCSP.security.default.provider", bccspSwProvider) } func TestTLSACAConfig(t *testing.T) { @@ -300,13 +285,13 @@ func TestTLSACAConfig(t *testing.T) { } func TestTimeouts(t *testing.T) { - myViper.Set("client.peer.timeout.connection", "2s") - myViper.Set("client.eventService.timeout.connection", "2m") - myViper.Set("client.eventService.timeout.registrationResponse", "2h") - myViper.Set("client.orderer.timeout.connection", "2ms") - myViper.Set("client.peer.timeout.queryResponse", "7h") - myViper.Set("client.peer.timeout.executeTxResponse", "8h") - myViper.Set("client.orderer.timeout.response", "6s") + configImpl.configViper.Set("client.peer.timeout.connection", "2s") + configImpl.configViper.Set("client.eventService.timeout.connection", "2m") + configImpl.configViper.Set("client.eventService.timeout.registrationResponse", "2h") + configImpl.configViper.Set("client.orderer.timeout.connection", "2ms") + configImpl.configViper.Set("client.peer.timeout.queryResponse", "7h") + configImpl.configViper.Set("client.peer.timeout.executeTxResponse", "8h") + configImpl.configViper.Set("client.orderer.timeout.response", "6s") t1 := configImpl.TimeoutOrDefault(api.Endorser) if t1 != time.Second*2 { @@ -338,7 +323,7 @@ func TestTimeouts(t *testing.T) { } // Test default - myViper.Set("client.orderer.timeout.connection", "") + configImpl.configViper.Set("client.orderer.timeout.connection", "") t1 = configImpl.TimeoutOrDefault(api.OrdererConnection) if t1 != time.Second*5 { t.Fatalf("Timeout not read correctly. Got: %s", t1) @@ -471,32 +456,32 @@ func TestInitConfigWithCmdRoot(t *testing.T) { logger.Infof("fileLoc is %s", fileLoc) logger.Infof("fileLoc right before calling InitConfigWithCmdRoot is %s", fileLoc) - _, err := InitConfigWithCmdRoot(fileLoc, cmdRoot) + config, err := InitConfigWithCmdRoot(fileLoc, cmdRoot) if err != nil { t.Fatalf("Failed to initialize config with cmd root. Error: %s", err) } //Test if Viper is initialized after calling init config - if myViper.GetString("client.BCCSP.security.hashAlgorithm") != configImpl.SecurityAlgorithm() { + if config.configViper.GetString("client.BCCSP.security.hashAlgorithm") != configImpl.SecurityAlgorithm() { t.Fatal("Config initialized with incorrect viper configuration") } } func TestInitConfigPanic(t *testing.T) { - existingLogLevel := myViper.Get("client.logging.level") - myViper.Set("client.logging.level", "INVALID") + + os.Setenv("FABRIC_SDK_CLIENT_LOGGING_LEVEL", "INVALID") defer func() { if r := recover(); r == nil { t.Errorf("Init config with cmdroot was supposed to panic") } else { //Setting it back during panic so as not to fail other tests - myViper.Set("client.logging.level", existingLogLevel) + os.Unsetenv("FABRIC_SDK_CLIENT_LOGGING_LEVEL") } - }() - InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", "fabric-sdk") + + InitConfig("../../test/fixtures/config/config_test.yaml") } func TestInitConfigInvalidLocation(t *testing.T) { @@ -521,7 +506,7 @@ func TestMultipleVipers(t *testing.T) { t.Fatalf("Expected testValue before config initialization got: %s", testValue1) } // initialize go sdk - _, err = InitConfig("../../test/fixtures/config/config_test.yaml") + config, err := InitConfig("../../test/fixtures/config/config_test.yaml") if err != nil { t.Log(err.Error()) } @@ -532,14 +517,14 @@ func TestMultipleVipers(t *testing.T) { t.Fatalf("Expected testvalue after config initialization") } // Make sure Go SDK config is unaffected - testValue3 := myViper.GetBool("client.BCCSP.security.softVerify") + testValue3 := config.configViper.GetBool("client.BCCSP.security.softVerify") if testValue3 != true { t.Fatalf("Expected existing config value to remain unchanged") } } func TestEnvironmentVariablesDefaultCmdRoot(t *testing.T) { - testValue := myViper.GetString("env.test") + testValue := configImpl.configViper.GetString("env.test") if testValue != "" { t.Fatalf("Expected environment variable value to be empty but got: %s", testValue) } @@ -551,19 +536,14 @@ func TestEnvironmentVariablesDefaultCmdRoot(t *testing.T) { t.Log(err.Error()) } - _, err = InitConfig("../../test/fixtures/config/config_test.yaml") - if err != nil { - t.Log(err.Error()) - } - - testValue = myViper.GetString("env.test") + testValue = configImpl.configViper.GetString("env.test") if testValue != "123" { t.Fatalf("Expected environment variable value but got: %s", testValue) } } func TestEnvironmentVariablesSpecificCmdRoot(t *testing.T) { - testValue := myViper.GetString("env.test") + testValue := configImpl.configViper.GetString("env.test") if testValue != "" { t.Fatalf("Expected environment variable value to be empty but got: %s", testValue) } @@ -575,12 +555,12 @@ func TestEnvironmentVariablesSpecificCmdRoot(t *testing.T) { t.Log(err.Error()) } - _, err = InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", "test_root") + config, err := InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", "test_root") if err != nil { t.Log(err.Error()) } - testValue = myViper.GetString("env.test") + testValue = config.configViper.GetString("env.test") if testValue != "456" { t.Fatalf("Expected environment variable value but got: %s", testValue) } diff --git a/pkg/fabric-ca-client/mocks/mockconfig.go b/pkg/fabric-ca-client/mocks/mockconfig.go index a8018b4c10..3fdcde54c0 100644 --- a/pkg/fabric-ca-client/mocks/mockconfig.go +++ b/pkg/fabric-ca-client/mocks/mockconfig.go @@ -13,7 +13,6 @@ import ( "github.com/hyperledger/fabric-sdk-go/api/apiconfig" bccspFactory "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory" - "github.com/spf13/viper" ) // MockConfig ... @@ -51,12 +50,6 @@ func (c *MockConfig) CAClientCertFile(org string) (string, error) { return "", nil } -// FabricClientViper returns the internal viper instance used by the -// SDK to read configuration options -func (c *MockConfig) FabricClientViper() *viper.Viper { - return nil -} - //TimeoutOrDefault not implemented func (c *MockConfig) TimeoutOrDefault(apiconfig.TimeoutType) time.Duration { return 0 diff --git a/pkg/fabric-client/mocks/mockconfig.go b/pkg/fabric-client/mocks/mockconfig.go index 3f9144f951..4df802fa61 100644 --- a/pkg/fabric-client/mocks/mockconfig.go +++ b/pkg/fabric-client/mocks/mockconfig.go @@ -10,8 +10,6 @@ import ( "crypto/x509" "time" - "github.com/spf13/viper" - config "github.com/hyperledger/fabric-sdk-go/api/apiconfig" "github.com/hyperledger/fabric-sdk-go/pkg/errors" @@ -64,12 +62,6 @@ func (c *MockConfig) TimeoutOrDefault(arg config.TimeoutType) time.Duration { return time.Second * 10 } -// FabricClientViper returns the internal viper instance used by the -// SDK to read configuration options -func (c *MockConfig) FabricClientViper() *viper.Viper { - return nil -} - // PeersConfig Retrieves the fabric peers from the config file provided func (c *MockConfig) PeersConfig(org string) ([]config.PeerConfig, error) { return nil, nil diff --git a/test/fixtures/config/config_test.yaml b/test/fixtures/config/config_test.yaml index e8ebe8aa8a..0770a3ecc2 100755 --- a/test/fixtures/config/config_test.yaml +++ b/test/fixtures/config/config_test.yaml @@ -154,7 +154,6 @@ channels: ledgerQuery: true eventSource: true - # # list of participating organizations in this network #