mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
tests: verify MultipleFileContentsByRef gets contents from the right path
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
07b2a1da87
commit
d82a0872c9
@ -113,7 +113,13 @@ func TestDirectoryResolver_MultipleFileContentsByRef(t *testing.T) {
|
|||||||
resolver := DirectoryResolver{"test-fixtures"}
|
resolver := DirectoryResolver{"test-fixtures"}
|
||||||
|
|
||||||
for _, p := range c.input {
|
for _, p := range c.input {
|
||||||
refs = append(refs, file.NewFileReference(p))
|
newRefs, err := resolver.FilesByPath(p)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not generate refs: %+v", err)
|
||||||
|
}
|
||||||
|
for _, ref := range newRefs {
|
||||||
|
refs = append(refs, ref)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contents, err := resolver.MultipleFileContentsByRef(refs...)
|
contents, err := resolver.MultipleFileContentsByRef(refs...)
|
||||||
|
|||||||
@ -92,7 +92,7 @@ func TestDirectoryScope(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultipleFileContentsByRef(t *testing.T) {
|
func TestMultipleFileContentsByRefContents(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
input string
|
input string
|
||||||
@ -105,12 +105,6 @@ func TestMultipleFileContentsByRef(t *testing.T) {
|
|||||||
path: "empty",
|
path: "empty",
|
||||||
expected: "",
|
expected: "",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
input: "test-fixtures/path-detected",
|
|
||||||
desc: "path does not exist",
|
|
||||||
path: "foo",
|
|
||||||
expected: "",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
input: "test-fixtures/path-detected",
|
input: "test-fixtures/path-detected",
|
||||||
desc: "file has contents",
|
desc: "file has contents",
|
||||||
@ -124,7 +118,16 @@ func TestMultipleFileContentsByRef(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("could not create NewDirScope: %w", err)
|
t.Errorf("could not create NewDirScope: %w", err)
|
||||||
}
|
}
|
||||||
ref := file.NewFileReference(file.Path(test.path))
|
refs, err := p.FilesByPath(file.Path(test.path))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not get file references from path: %s, %v", test.path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(refs) != 1 {
|
||||||
|
t.Errorf("expected a single ref to be generated but got: %d", len(refs))
|
||||||
|
}
|
||||||
|
ref := refs[0]
|
||||||
|
|
||||||
contents, err := p.MultipleFileContentsByRef(ref)
|
contents, err := p.MultipleFileContentsByRef(ref)
|
||||||
content := contents[ref]
|
content := contents[ref]
|
||||||
|
|
||||||
@ -136,6 +139,38 @@ func TestMultipleFileContentsByRef(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMultipleFileContentsByRefNoContents(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
input string
|
||||||
|
path string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: "test-fixtures/path-detected",
|
||||||
|
desc: "path does not exist",
|
||||||
|
path: "foo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range testCases {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
p, err := NewScopeFromDir(test.input, AllLayersScope)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not create NewDirScope: %w", err)
|
||||||
|
}
|
||||||
|
refs, err := p.FilesByPath(file.Path(test.path))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("could not get file references from path: %s, %v", test.path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(refs) != 0 {
|
||||||
|
t.Errorf("didnt' expect a ref, but got: %d", len(refs))
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFilesByGlob(t *testing.T) {
|
func TestFilesByGlob(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user