order locations by container layer order (#3858)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2025-05-13 00:02:07 -04:00
committed by GitHub
parent e3e69596bd
commit 59b880f26a
18 changed files with 1589 additions and 83 deletions
@@ -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")