mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-14 22:18:20 +00:00
4966300c96
* Update spectests to v1.1.0-beta.1 from hf1 branch * fix params loading
39 lines
853 B
Go
39 lines
853 B
Go
package testutil
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path"
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// BazelDirectoryNonEmpty returns true if directory exists and is not empty.
|
|
func BazelDirectoryNonEmpty(filePath string) (bool, error) {
|
|
p, err := bazel.Runfile(filePath)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
fs, err := ioutil.ReadDir(p)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return len(fs) > 0, nil
|
|
}
|
|
|
|
// BazelFileBytes returns the byte array of the bazel file path given.
|
|
func BazelFileBytes(filePaths ...string) ([]byte, error) {
|
|
filepath, err := bazel.Runfile(path.Join(filePaths...))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fileBytes, err := ioutil.ReadFile(filepath) // #nosec G304
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(fileBytes) == 0 {
|
|
return nil, errors.New("empty file")
|
|
}
|
|
return fileBytes, nil
|
|
}
|