2021-09-17 01:32:23 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/bazelbuild/rules_go/go/tools/bazel"
|
2021-09-17 21:55:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/io/file"
|
2021-09-17 01:32:23 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RetrieveFiles(name string, t *testing.T) ([]string, [][]byte) {
|
|
|
|
filepath, err := bazel.Runfile(name)
|
|
|
|
require.NoError(t, err)
|
|
|
|
testFiles, err := ioutil.ReadDir(filepath)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fileNames := []string{}
|
|
|
|
fileContent := [][]byte{}
|
|
|
|
require.Equal(t, false, len(testFiles) == 0, "no files exist in directory")
|
|
|
|
for _, f := range testFiles {
|
|
|
|
// Remove .yml suffix
|
|
|
|
fName := strings.TrimSuffix(f.Name(), ".yaml")
|
|
|
|
fileNames = append(fileNames, fName)
|
2021-09-17 21:55:24 +00:00
|
|
|
data, err := file.ReadFileAsBytes(path.Join(filepath, f.Name()))
|
2021-09-17 01:32:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
fileContent = append(fileContent, data)
|
|
|
|
}
|
|
|
|
return fileNames, fileContent
|
|
|
|
}
|