mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +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"}
|
||||
|
||||
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...)
|
||||
|
||||
@ -92,7 +92,7 @@ func TestDirectoryScope(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleFileContentsByRef(t *testing.T) {
|
||||
func TestMultipleFileContentsByRefContents(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
input string
|
||||
@ -105,12 +105,6 @@ func TestMultipleFileContentsByRef(t *testing.T) {
|
||||
path: "empty",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
input: "test-fixtures/path-detected",
|
||||
desc: "path does not exist",
|
||||
path: "foo",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
input: "test-fixtures/path-detected",
|
||||
desc: "file has contents",
|
||||
@ -124,7 +118,16 @@ func TestMultipleFileContentsByRef(t *testing.T) {
|
||||
if err != nil {
|
||||
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)
|
||||
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) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user