github.com/yandex/pandora@v0.5.32/core/coretest/config.go (about) 1 package coretest 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/spf13/viper" 8 "github.com/stretchr/testify/require" 9 "github.com/yandex/pandora/core/config" 10 ) 11 12 func DecodeT(t *testing.T, data string, result interface{}) { 13 conf := ParseYAML(t, data) 14 err := config.Decode(conf, result) 15 require.NoError(t, err) 16 } 17 18 func DecodeAndValidateT(t *testing.T, data string, result interface{}) { 19 DecodeT(t, data, result) 20 err := config.Validate(result) 21 require.NoError(t, err) 22 } 23 24 func ParseYAML(t *testing.T, data string) map[string]interface{} { 25 v := viper.New() 26 v.SetConfigType("yaml") 27 err := v.ReadConfig(strings.NewReader(data)) 28 require.NoError(t, err) 29 return v.AllSettings() 30 }