Refactor more code to use testutils.WasCalled (#13054)
* Refactor more code to use testutils.WasCalled * incorporate review comments * Revert watcher_test.go changes The file is in config package and the other tests use config_test. So it is not visible.
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
0c8b580458
Коммит
2db6823f5d
@@ -11,8 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/utils/testutils"
|
||||
)
|
||||
|
||||
func TestWatcherInvalidDirectory(t *testing.T) {
|
||||
@@ -49,9 +47,17 @@ func TestWatcher(t *testing.T) {
|
||||
|
||||
// Write to a different file
|
||||
ioutil.WriteFile(filepath.Join(tempDir, "unrelated"), []byte("data"), 0644)
|
||||
require.False(t, testutils.WasCalled(called, 1*time.Second), "callback should not have been called for unrelated file")
|
||||
select {
|
||||
case <-called:
|
||||
t.Fatal("callback should not have been called for unrelated file")
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
|
||||
// Write to the watched file
|
||||
ioutil.WriteFile(f.Name(), []byte("data"), 0644)
|
||||
require.True(t, testutils.WasCalled(called, 5*time.Second), "callback should have been called when file written")
|
||||
select {
|
||||
case <-called:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("callback should have been called when file written")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user