From c2799b35d8b9472b41ab5e58a36b14da8176ff5b Mon Sep 17 00:00:00 2001 From: Dan Luhring Date: Mon, 4 Jan 2021 14:18:51 -0500 Subject: [PATCH] Fix mock resolver interface implementation Signed-off-by: Dan Luhring --- syft/source/mock_resolver.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/syft/source/mock_resolver.go b/syft/source/mock_resolver.go index 03f67fb47..3710937b7 100644 --- a/syft/source/mock_resolver.go +++ b/syft/source/mock_resolver.go @@ -2,7 +2,7 @@ package source import ( "fmt" - "io/ioutil" + "io" "os" "github.com/anchore/syft/internal/file" @@ -35,19 +35,19 @@ func (r MockResolver) String() string { // FileContentsByLocation fetches file contents for a single location. If the // path does not exist, an error is returned. -func (r MockResolver) FileContentsByLocation(location Location) (string, error) { +func (r MockResolver) FileContentsByLocation(location Location) (io.ReadCloser, error) { for _, l := range r.Locations { if l == location { - return stringContent(location.Path) + return os.Open(location.Path) } } - return "", fmt.Errorf("no file for location: %v", location) + return nil, fmt.Errorf("no file for location: %v", location) } // MultipleFileContentsByLocation returns the file contents for all specified Locations. -func (r MockResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]string, error) { - results := make(map[Location]string) +func (r MockResolver) MultipleFileContentsByLocation(locations []Location) (map[Location]io.ReadCloser, error) { + results := make(map[Location]io.ReadCloser) for _, l := range locations { contents, err := r.FileContentsByLocation(l) if err != nil { @@ -100,17 +100,3 @@ func (r MockResolver) RelativeFileByPath(_ Location, path string) *Location { return &paths[0] } - -func stringContent(path string) (string, error) { - reader, err := os.Open(path) - if err != nil { - return "", err - } - - b, err := ioutil.ReadAll(reader) - if err != nil { - return "", err - } - - return string(b), nil -}