This repository was archived by the owner on Dec 15, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1552,6 +1552,7 @@ func (v *Viper) SetRawConfig(config map[string]interface{}) {
15521552 insensitiviseMap (config )
15531553 v .config = config
15541554 v .configChangedAt = time .Now ()
1555+ v .cache .Clear ()
15551556}
15561557
15571558// MergeInConfig merges a new configuration with an existing config.
Original file line number Diff line number Diff line change @@ -2553,9 +2553,24 @@ bar:
25532553}
25542554
25552555func TestSetRawConfig (t * testing.T ) {
2556- Reset ()
2557- SetRawConfig (map [string ]interface {}{"foo" : "bar" })
2558- assert .Equal (t , "bar" , Get ("foo" ))
2556+ t .Run ("case=setting the config map works" , func (t * testing.T ) {
2557+ v := New ()
2558+ v .SetRawConfig (map [string ]interface {}{"foo" : "bar" })
2559+ assert .Equal (t , "bar" , v .Get ("foo" ))
2560+ })
2561+
2562+ t .Run ("case=resets cache" , func (t * testing.T ) {
2563+ key := "foo"
2564+ v := New ()
2565+ // make sure the value is in the cache
2566+ for ! v .cache .Set (key , "bar" , 0 ) {
2567+ }
2568+ for _ , ok := v .cache .Get (key ); ! ok ; _ , ok = v .cache .Get (key ) {
2569+ }
2570+
2571+ v .SetRawConfig (map [string ]interface {}{key : "not bar" })
2572+ assert .Equal (t , "not bar" , v .Get (key ))
2573+ })
25592574}
25602575
25612576func BenchmarkGetBool (b * testing.B ) {
You can’t perform that action at this time.
0 commit comments