mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 07:26:34 +01:00
fix tests to use location instead of file.Reference
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -2,8 +2,6 @@ package source
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/stereoscope/pkg/file"
|
||||
)
|
||||
|
||||
func TestDirectoryResolver_FilesByPath(t *testing.T) {
|
||||
@@ -58,7 +56,7 @@ func TestDirectoryResolver_FilesByPath(t *testing.T) {
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
resolver := DirectoryResolver{c.root}
|
||||
refs, err := resolver.FilesByPath(file.Path(c.input))
|
||||
refs, err := resolver.FilesByPath(c.input)
|
||||
if err != nil {
|
||||
t.Fatalf("could not use resolver: %+v, %+v", err, refs)
|
||||
}
|
||||
@@ -68,7 +66,7 @@ func TestDirectoryResolver_FilesByPath(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, actual := range refs {
|
||||
if actual.Path != file.Path(c.expected) {
|
||||
if actual.Path != c.expected {
|
||||
t.Errorf("bad resolve path: '%s'!='%s'", actual.Path, c.expected)
|
||||
}
|
||||
}
|
||||
@@ -79,22 +77,22 @@ func TestDirectoryResolver_FilesByPath(t *testing.T) {
|
||||
func TestDirectoryResolver_MultipleFilesByPath(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
input []file.Path
|
||||
input []string
|
||||
refCount int
|
||||
}{
|
||||
{
|
||||
name: "finds multiple files",
|
||||
input: []file.Path{file.Path("test-fixtures/image-symlinks/file-1.txt"), file.Path("test-fixtures/image-symlinks/file-2.txt")},
|
||||
input: []string{"test-fixtures/image-symlinks/file-1.txt", "test-fixtures/image-symlinks/file-2.txt"},
|
||||
refCount: 2,
|
||||
},
|
||||
{
|
||||
name: "skips non-existing files",
|
||||
input: []file.Path{file.Path("test-fixtures/image-symlinks/bogus.txt"), file.Path("test-fixtures/image-symlinks/file-1.txt")},
|
||||
input: []string{"test-fixtures/image-symlinks/bogus.txt", "test-fixtures/image-symlinks/file-1.txt"},
|
||||
refCount: 1,
|
||||
},
|
||||
{
|
||||
name: "does not return anything for non-existing directories",
|
||||
input: []file.Path{file.Path("test-fixtures/non-existing/bogus.txt"), file.Path("test-fixtures/non-existing/file-1.txt")},
|
||||
input: []string{"test-fixtures/non-existing/bogus.txt", "test-fixtures/non-existing/file-1.txt"},
|
||||
refCount: 0,
|
||||
},
|
||||
}
|
||||
@@ -117,47 +115,47 @@ func TestDirectoryResolver_MultipleFilesByPath(t *testing.T) {
|
||||
func TestDirectoryResolver_MultipleFileContentsByRef(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
input []file.Path
|
||||
input []string
|
||||
refCount int
|
||||
contents []string
|
||||
}{
|
||||
{
|
||||
name: "gets multiple file contents",
|
||||
input: []file.Path{file.Path("test-fixtures/image-symlinks/file-1.txt"), file.Path("test-fixtures/image-symlinks/file-2.txt")},
|
||||
input: []string{"test-fixtures/image-symlinks/file-1.txt", "test-fixtures/image-symlinks/file-2.txt"},
|
||||
refCount: 2,
|
||||
},
|
||||
{
|
||||
name: "skips non-existing files",
|
||||
input: []file.Path{file.Path("test-fixtures/image-symlinks/bogus.txt"), file.Path("test-fixtures/image-symlinks/file-1.txt")},
|
||||
input: []string{"test-fixtures/image-symlinks/bogus.txt", "test-fixtures/image-symlinks/file-1.txt"},
|
||||
refCount: 1,
|
||||
},
|
||||
{
|
||||
name: "does not return anything for non-existing directories",
|
||||
input: []file.Path{file.Path("test-fixtures/non-existing/bogus.txt"), file.Path("test-fixtures/non-existing/file-1.txt")},
|
||||
input: []string{"test-fixtures/non-existing/bogus.txt", "test-fixtures/non-existing/file-1.txt"},
|
||||
refCount: 0,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
refs := make([]file.Reference, 0)
|
||||
locations := make([]Location, 0)
|
||||
resolver := DirectoryResolver{"test-fixtures"}
|
||||
|
||||
for _, p := range c.input {
|
||||
newRefs, err := resolver.FilesByPath(p)
|
||||
if err != nil {
|
||||
t.Errorf("could not generate refs: %+v", err)
|
||||
t.Errorf("could not generate locations: %+v", err)
|
||||
}
|
||||
for _, ref := range newRefs {
|
||||
refs = append(refs, ref)
|
||||
locations = append(locations, ref)
|
||||
}
|
||||
}
|
||||
|
||||
contents, err := resolver.MultipleFileContentsByRef(refs...)
|
||||
contents, err := resolver.MultipleFileContentsByLocation(locations)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to generate file contents by ref: %+v", err)
|
||||
}
|
||||
if len(contents) != c.refCount {
|
||||
t.Errorf("unexpected number of refs produced: %d != %d", len(contents), c.refCount)
|
||||
t.Errorf("unexpected number of locations produced: %d != %d", len(contents), c.refCount)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user