mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 15:36:41 +01:00
remove multi* content fetching from resolvers
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -57,7 +57,7 @@ func TestDirectoryResolver_FilesByPath(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
resolver := DirectoryResolver{c.root}
|
||||
resolver := directoryResolver{c.root}
|
||||
|
||||
hasPath := resolver.HasPath(c.input)
|
||||
if !c.forcePositiveHasPath {
|
||||
@@ -112,7 +112,7 @@ func TestDirectoryResolver_MultipleFilesByPath(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
resolver := DirectoryResolver{"test-fixtures"}
|
||||
resolver := directoryResolver{"test-fixtures"}
|
||||
|
||||
refs, err := resolver.FilesByPath(c.input...)
|
||||
if err != nil {
|
||||
@@ -126,59 +126,9 @@ func TestDirectoryResolver_MultipleFilesByPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirectoryResolver_MultipleFileContentsByRef(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
input []string
|
||||
refCount int
|
||||
contents []string
|
||||
}{
|
||||
{
|
||||
name: "gets multiple file contents",
|
||||
input: []string{"test-fixtures/image-symlinks/file-1.txt", "test-fixtures/image-symlinks/file-2.txt"},
|
||||
refCount: 2,
|
||||
},
|
||||
{
|
||||
name: "skips non-existing files",
|
||||
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: []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) {
|
||||
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 locations: %+v", err)
|
||||
}
|
||||
for _, ref := range newRefs {
|
||||
locations = append(locations, ref)
|
||||
}
|
||||
}
|
||||
|
||||
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 locations produced: %d != %d", len(contents), c.refCount)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDirectoryResolver_FilesByGlobMultiple(t *testing.T) {
|
||||
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||
resolver := DirectoryResolver{"test-fixtures"}
|
||||
resolver := directoryResolver{"test-fixtures"}
|
||||
refs, err := resolver.FilesByGlob("image-symlinks/file*")
|
||||
|
||||
if err != nil {
|
||||
@@ -195,7 +145,7 @@ func TestDirectoryResolver_FilesByGlobMultiple(t *testing.T) {
|
||||
|
||||
func TestDirectoryResolver_FilesByGlobRecursive(t *testing.T) {
|
||||
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||
resolver := DirectoryResolver{"test-fixtures/image-symlinks"}
|
||||
resolver := directoryResolver{"test-fixtures/image-symlinks"}
|
||||
refs, err := resolver.FilesByGlob("**/*.txt")
|
||||
|
||||
if err != nil {
|
||||
@@ -212,7 +162,7 @@ func TestDirectoryResolver_FilesByGlobRecursive(t *testing.T) {
|
||||
|
||||
func TestDirectoryResolver_FilesByGlobSingle(t *testing.T) {
|
||||
t.Run("finds multiple matching files", func(t *testing.T) {
|
||||
resolver := DirectoryResolver{"test-fixtures"}
|
||||
resolver := directoryResolver{"test-fixtures"}
|
||||
refs, err := resolver.FilesByGlob("image-symlinks/*1.txt")
|
||||
if err != nil {
|
||||
t.Fatalf("could not use resolver: %+v, %+v", err, refs)
|
||||
|
||||
Reference in New Issue
Block a user