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.
Этот коммит содержится в:
Agniva De Sarker
2019-11-13 13:41:26 +05:30
коммит произвёл Saturnino Abril
родитель 0c8b580458
Коммит 2db6823f5d
5 изменённых файлов: 30 добавлений и 62 удалений

Просмотреть файл

@@ -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")
}
}