Skip to content

Commit 008ece3

Browse files
committed
FAB-15519 remove viperutil.EnhancedExactUnmarshalKey
FAB-15519 #done Change-Id: I93678d6907bbde18f8cc11dba086031699cba9ad Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
1 parent e045a5a commit 008ece3

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

common/viperutil/config_test.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -445,54 +445,6 @@ func TestStringFromFileEnv(t *testing.T) {
445445

446446
}
447447

448-
func TestEnhancedExactUnmarshalKey(t *testing.T) {
449-
type Nested struct {
450-
Key string
451-
BoolVar bool
452-
}
453-
454-
type nestedKey struct {
455-
Nested Nested
456-
}
457-
458-
yaml := "---\n" +
459-
"Top:\n" +
460-
" Nested:\n" +
461-
" Nested:\n" +
462-
" Key: BAD\n" +
463-
" BoolVar: true\n"
464-
465-
envVar := "VIPERUTIL_TOP_NESTED_NESTED_KEY"
466-
envVal := "GOOD"
467-
os.Setenv(envVar, envVal)
468-
defer os.Unsetenv(envVar)
469-
470-
viper.SetEnvPrefix(Prefix)
471-
defer viper.Reset()
472-
viper.AutomaticEnv()
473-
replacer := strings.NewReplacer(".", "_")
474-
viper.SetEnvKeyReplacer(replacer)
475-
viper.SetConfigType("yaml")
476-
477-
if err := viper.ReadConfig(bytes.NewReader([]byte(yaml))); err != nil {
478-
t.Fatalf("Error reading config: %s", err)
479-
}
480-
481-
var uconf nestedKey
482-
if err := EnhancedExactUnmarshalKey("top.Nested", &uconf); err != nil {
483-
t.Fatalf("Failed to unmarshall: %s", err)
484-
}
485-
486-
if uconf.Nested.Key != envVal {
487-
t.Fatalf(`Expected: "%s", Actual: "%s"`, envVal, uconf.Nested.Key)
488-
}
489-
490-
if uconf.Nested.BoolVar != true {
491-
t.Fatalf(`Expected: "%t", Actual: "%t"`, true, uconf.Nested.BoolVar)
492-
}
493-
494-
}
495-
496448
func TestDecodeOpaqueField(t *testing.T) {
497449
yaml := `---
498450
Foo: bar

common/viperutil/config_util.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,25 +313,3 @@ func EnhancedExactUnmarshal(v *viper.Viper, output interface{}) error {
313313
}
314314
return decoder.Decode(leafKeys)
315315
}
316-
317-
// EnhancedExactUnmarshalKey is intended to unmarshal a config file subtreee into a structure
318-
func EnhancedExactUnmarshalKey(baseKey string, output interface{}) error {
319-
m := make(map[string]interface{})
320-
m[baseKey] = nil
321-
leafKeys := getKeysRecursively("", viper.Get, m)
322-
323-
logger.Debugf("%+v", leafKeys)
324-
325-
config := &mapstructure.DecoderConfig{
326-
Metadata: nil,
327-
Result: output,
328-
WeaklyTypedInput: true,
329-
}
330-
331-
decoder, err := mapstructure.NewDecoder(config)
332-
if err != nil {
333-
return err
334-
}
335-
336-
return decoder.Decode(leafKeys[baseKey])
337-
}

0 commit comments

Comments
 (0)