diff --git a/orderer/config/config_test.go b/orderer/config/config_test.go index eb9d2546e43..0ceccd05c4b 100644 --- a/orderer/config/config_test.go +++ b/orderer/config/config_test.go @@ -23,6 +23,7 @@ import ( "reflect" "strings" "testing" + "time" "github.com/spf13/viper" ) @@ -97,17 +98,25 @@ func TestEnvSlice(t *testing.T) { // a bug in the original viper implementation that is worked around in // the Load codepath for now func TestEnvInnerVar(t *testing.T) { - envVar := "ORDERER_GENERAL_LISTENPORT" - envVal := uint16(80) - os.Setenv(envVar, fmt.Sprintf("%d", envVal)) - defer os.Unsetenv(envVar) + envVar1 := "ORDERER_GENERAL_LISTENPORT" + envVal1 := uint16(80) + envVar2 := "ORDERER_KAFKA_RETRY_PERIOD" + envVal2 := "42s" + os.Setenv(envVar1, fmt.Sprintf("%d", envVal1)) + os.Setenv(envVar2, envVal2) + defer os.Unsetenv(envVar1) + defer os.Unsetenv(envVar2) config := Load() if config == nil { t.Fatalf("Could not load config") } - if config.General.ListenPort != envVal { - t.Fatalf("Environmental override of inner config did not work") + if config.General.ListenPort != envVal1 { + t.Fatalf("Environmental override of inner config test 1 did not work") + } + v2, _ := time.ParseDuration(envVal2) + if config.Kafka.Retry.Period != v2 { + t.Fatalf("Environmental override of inner config test 2 did not work") } } diff --git a/orderer/config/config_util.go b/orderer/config/config_util.go index aed5e0bac07..9707447e5d8 100644 --- a/orderer/config/config_util.go +++ b/orderer/config/config_util.go @@ -31,7 +31,7 @@ func getKeysRecursively(base string, v *viper.Viper, nodeKeys map[string]interfa fqKey := base + key val := v.Get(fqKey) if m, ok := val.(map[interface{}]interface{}); ok { - logger.Debugf("Found map value for %s", fqKey) + logger.Debugf("Found map[interface{}]interface{} value for %s", fqKey) tmp := make(map[string]interface{}) for ik, iv := range m { cik, ok := ik.(string) @@ -41,6 +41,9 @@ func getKeysRecursively(base string, v *viper.Viper, nodeKeys map[string]interfa tmp[cik] = iv } result[key] = getKeysRecursively(fqKey+".", v, tmp) + } else if m, ok := val.(map[string]interface{}); ok { + logger.Debugf("Found map[string]interface{} value for %s", fqKey) + result[key] = getKeysRecursively(fqKey+".", v, m) } else { logger.Debugf("Found real value for %s setting to %T %v", fqKey, val, val) result[key] = val