mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
* Convert config/watcher_test.go t.Fatal calls into require calls * Moved wasCalled to a public helper function Now the testutils package has a new function WasCalled that can be used by anywhere.
42 lines
863 B
Go
42 lines
863 B
Go
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package testutils
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/mattermost/mattermost-server/utils/fileutils"
|
|
)
|
|
|
|
func ReadTestFile(name string) ([]byte, error) {
|
|
path, _ := fileutils.FindDir("tests")
|
|
file, err := os.Open(filepath.Join(path, name))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
data := &bytes.Buffer{}
|
|
if _, err := io.Copy(data, file); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return data.Bytes(), nil
|
|
}
|
|
}
|
|
|
|
// WasCalled reports whether a given callback channel was called
|
|
// within the specified time duration or not.
|
|
func WasCalled(c chan bool, duration time.Duration) bool {
|
|
wasCalled := false
|
|
select {
|
|
case <-c:
|
|
wasCalled = true
|
|
case <-time.After(duration):
|
|
}
|
|
return wasCalled
|
|
}
|