mattermost/utils/testutils/testutils.go
Agniva De Sarker 8ab0e80b77 MM-19022: Convert config/watcher_test.go t.Fatal calls into require calls (#12524)
* 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.
2019-10-02 18:57:43 +02:00

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
}