MCPcopy
hub / github.com/spf13/viper / TestMergeConfig

Function TestMergeConfig

viper_test.go:2064–2091  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2062`)
2063
2064func TestMergeConfig(t *testing.T) {
2065 v := New()
2066 v.SetConfigType("yml")
2067 err := v.ReadConfig(bytes.NewBuffer(yamlMergeExampleTgt))
2068 require.NoError(t, err)
2069
2070 assert.Equal(t, 37890, v.GetInt("hello.pop"))
2071 assert.Equal(t, int32(37890), v.GetInt32("hello.pop"))
2072 assert.Equal(t, int64(765432101234567), v.GetInt64("hello.largenum"))
2073 assert.Equal(t, uint8(2), v.GetUint8("hello.pop"))
2074 assert.Equal(t, uint(37890), v.GetUint("hello.pop"))
2075 assert.Equal(t, uint16(37890), v.GetUint16("hello.pop"))
2076 assert.Equal(t, uint32(37890), v.GetUint32("hello.pop"))
2077 assert.Equal(t, uint64(9223372036854775808), v.GetUint64("hello.num2pow63"))
2078 assert.Len(t, v.GetStringSlice("hello.world"), 4)
2079 assert.Empty(t, v.GetString("fu"))
2080
2081 err = v.MergeConfig(bytes.NewBuffer(yamlMergeExampleSrc))
2082 require.NoError(t, err)
2083
2084 assert.Equal(t, 45000, v.GetInt("hello.pop"))
2085 assert.Equal(t, int32(45000), v.GetInt32("hello.pop"))
2086 assert.Equal(t, int64(7654321001234567), v.GetInt64("hello.largenum"))
2087 assert.Len(t, v.GetStringSlice("hello.world"), 4)
2088 assert.Len(t, v.GetStringSlice("hello.universe"), 2)
2089 assert.Len(t, v.GetIntSlice("hello.ints"), 2)
2090 assert.Equal(t, "bar", v.GetString("fu"))
2091}
2092
2093func TestMergeConfigWithSetConfigFile(t *testing.T) {
2094 v := New()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.85
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
GetIntMethod · 0.80
GetInt32Method · 0.80
GetInt64Method · 0.80
GetUint8Method · 0.80
GetUintMethod · 0.80
GetUint16Method · 0.80
GetUint32Method · 0.80
GetUint64Method · 0.80
GetStringSliceMethod · 0.80

Tested by

no test coverage detected