mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 06:26:30 +01:00
Add layer information for go-module-binary-cataloger (#620)
* update functions to pass Location Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * update unit tests to pass new locations Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * fix image source.FileResolvers to include layer info Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add non-empty location in golang binary cataloger testing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Co-authored-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
co-authored by
Alex Goodman
parent
bb0f35bac4
commit
9bbc9ff633
@@ -198,7 +198,7 @@ func (r *allLayersResolver) FilesByMIMEType(types ...string) ([]Location, error)
|
||||
}
|
||||
|
||||
for _, ref := range refs {
|
||||
locations = append(locations, NewLocationFromReference(ref))
|
||||
locations = append(locations, NewLocationFromImage(string(ref.RealPath), ref, r.img))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -272,3 +272,32 @@ func Test_imageAllLayersResolver_FilesByMIMEType(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_imageAllLayersResolver_hasFilesystemIDInLocation(t *testing.T) {
|
||||
img := imagetest.GetFixtureImage(t, "docker-archive", "image-duplicate-path")
|
||||
|
||||
resolver, err := newAllLayersResolver(img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
locations, err := resolver.FilesByMIMEType("text/plain")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
locations, err = resolver.FilesByGlob("*.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
locations, err = resolver.FilesByPath("/somefile-1.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ func (r *imageSquashResolver) FilesByMIMEType(types ...string) ([]Location, erro
|
||||
|
||||
var locations []Location
|
||||
for _, ref := range refs {
|
||||
locations = append(locations, NewLocationFromReference(ref))
|
||||
locations = append(locations, NewLocationFromImage(string(ref.RealPath), ref, r.img))
|
||||
}
|
||||
|
||||
return locations, nil
|
||||
|
||||
@@ -259,3 +259,32 @@ func Test_imageSquashResolver_FilesByMIMEType(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_imageSquashResolver_hasFilesystemIDInLocation(t *testing.T) {
|
||||
img := imagetest.GetFixtureImage(t, "docker-archive", "image-duplicate-path")
|
||||
|
||||
resolver, err := newImageSquashResolver(img)
|
||||
assert.NoError(t, err)
|
||||
|
||||
locations, err := resolver.FilesByMIMEType("text/plain")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
locations, err = resolver.FilesByGlob("*.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
locations, err = resolver.FilesByPath("/somefile-1.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, locations)
|
||||
for _, location := range locations {
|
||||
assert.NotEmpty(t, location.FileSystemID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,14 +53,6 @@ func NewLocationFromDirectory(responsePath string, ref file.Reference) Location
|
||||
}
|
||||
}
|
||||
|
||||
func NewLocationFromReference(ref file.Reference) Location {
|
||||
return Location{
|
||||
VirtualPath: string(ref.RealPath),
|
||||
RealPath: string(ref.RealPath),
|
||||
ref: ref,
|
||||
}
|
||||
}
|
||||
|
||||
func (l Location) String() string {
|
||||
str := ""
|
||||
if l.ref.ID() != 0 {
|
||||
|
||||
Reference in New Issue
Block a user