mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
order locations by container layer order (#3858)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,9 @@ package fileresolver
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -516,8 +518,8 @@ func compareLocations(t *testing.T, expected, actual []file.Location) {
|
||||
ignoreMetadata := cmpopts.IgnoreFields(file.LocationMetadata{}, "Annotations")
|
||||
ignoreFS := cmpopts.IgnoreFields(file.Coordinates{}, "FileSystemID")
|
||||
|
||||
sort.Sort(file.Locations(expected))
|
||||
sort.Sort(file.Locations(actual))
|
||||
slices.SortFunc(expected, locationSorter)
|
||||
slices.SortFunc(actual, locationSorter)
|
||||
|
||||
if d := cmp.Diff(expected, actual,
|
||||
ignoreUnexported,
|
||||
@@ -531,6 +533,16 @@ func compareLocations(t *testing.T, expected, actual []file.Location) {
|
||||
|
||||
}
|
||||
|
||||
// locationSorter always sorts only by path information since test fixtures here only have filesystem IDs
|
||||
// for one side of the comparison (expected) and not the other (actual).
|
||||
func locationSorter(a, b file.Location) int {
|
||||
if a.AccessPath != b.AccessPath {
|
||||
return strings.Compare(a.AccessPath, b.AccessPath)
|
||||
}
|
||||
|
||||
return strings.Compare(a.RealPath, b.RealPath)
|
||||
}
|
||||
|
||||
func TestSquashResolver_AllLocations(t *testing.T) {
|
||||
img := imagetest.GetFixtureImage(t, "docker-archive", "image-files-deleted")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user