test(windows): fix watch file test

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2021-09-22 10:39:19 +02:00 committed by Márk Sági-Kazár
parent 552e3bd0ca
commit 15c88da25c

View file

@ -2346,10 +2346,13 @@ func TestWatchFile(t *testing.T) {
t.Logf("test config file: %s\n", configFile) t.Logf("test config file: %s\n", configFile)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
var wgDoneOnce sync.Once // OnConfigChange is called twice on Windows
v.OnConfigChange(func(in fsnotify.Event) { v.OnConfigChange(func(in fsnotify.Event) {
t.Logf("config file changed") t.Logf("config file changed")
wgDoneOnce.Do(func() {
wg.Done() wg.Done()
}) })
})
v.WatchConfig() v.WatchConfig()
// when overwriting the file and waiting for the custom change notification handler to be triggered // 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)