diff --git a/viper.go b/viper.go index bda3ea8..630d9df 100644 --- a/viper.go +++ b/viper.go @@ -319,7 +319,7 @@ func (v *Viper) WatchConfig() { realConfigFile = currentConfigFile err := v.ReadInConfig() if err != nil { - log.Printf("error reading file: %v\n", err) + log.Printf("error reading config file: %v\n", err) } if v.onConfigChange != nil { v.onConfigChange(event) @@ -343,7 +343,6 @@ func (v *Viper) WatchConfig() { initWG.Done() // done initalizing the watch in this go routine, so the parent routine can move on... eventsWG.Wait() // now, wait for event loop to end in this go-routine... }() - fmt.Println(" init WG done") initWG.Wait() // make sure that the go routine above fully ended before returning } diff --git a/viper_test.go b/viper_test.go index 7acd910..76ec02e 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1469,17 +1469,19 @@ func TestWatchFile(t *testing.T) { t.Run("file content changed", func(t *testing.T) { // given a `config.yaml` file being watched v, configFile, cleanup := newViperWithConfigFile(t) - fmt.Printf("test config file: %s\n", configFile) defer cleanup() + _, err := os.Stat(configFile) + require.NoError(t, err) + t.Logf("test config file: %s\n", configFile) wg := sync.WaitGroup{} wg.Add(1) - v.WatchConfig() v.OnConfigChange(func(in fsnotify.Event) { t.Logf("config file changed") wg.Done() }) + v.WatchConfig() // when overwriting the file and waiting for the custom change notification handler to be triggered - err := ioutil.WriteFile(configFile, []byte("foo: baz\n"), 0640) + err = ioutil.WriteFile(configFile, []byte("foo: baz\n"), 0640) wg.Wait() // then the config value should have changed require.Nil(t, err)