github.com/prysmaticlabs/prysm@v1.4.4/shared/testutil/bazel.go (about)

     1  package testutil
     2  
     3  import (
     4  	"io/ioutil"
     5  	"path"
     6  
     7  	"github.com/bazelbuild/rules_go/go/tools/bazel"
     8  )
     9  
    10  // BazelDirectoryNonEmpty returns true if directory exists and is not empty.
    11  func BazelDirectoryNonEmpty(filePath string) (bool, error) {
    12  	p, err := bazel.Runfile(filePath)
    13  	if err != nil {
    14  		return false, err
    15  	}
    16  	fs, err := ioutil.ReadDir(p)
    17  	if err != nil {
    18  		return false, err
    19  	}
    20  	return len(fs) > 0, nil
    21  }
    22  
    23  // BazelFileBytes returns the byte array of the bazel file path given.
    24  func BazelFileBytes(filePaths ...string) ([]byte, error) {
    25  	filepath, err := bazel.Runfile(path.Join(filePaths...))
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  	fileBytes, err := ioutil.ReadFile(filepath)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	return fileBytes, nil
    34  }