mirror of
https://github.com/anchore/syft.git
synced 2026-11-26 13:44:11 +01:00
fix(python): sort uv.lock extras by name so the SBOM output is stable (#5468)
Signed-off-by: Wleeaf <179125857+wleeaf@users.noreply.github.com> Co-authored-by: Wleeaf <179125857+wleeaf@users.noreply.github.com>
This commit is contained in:
@@ -137,6 +137,9 @@ func extractUvExtras(p uvPackage) []pkg.PythonUvLockExtraEntry {
|
|||||||
Dependencies: extraDeps,
|
Dependencies: extraDeps,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
sort.Slice(extras, func(i, j int) bool {
|
||||||
|
return extras[i].Name < extras[j].Name
|
||||||
|
})
|
||||||
return extras
|
return extras
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
@@ -253,3 +255,23 @@ func TestParseUvLockWithLicenseEnrichment(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExtractUvExtrasIsSortedByName(t *testing.T) {
|
||||||
|
p := uvPackage{
|
||||||
|
OptionalDependencies: map[string]uvDependencies{
|
||||||
|
"socks": {{Name: "socksio"}},
|
||||||
|
"brotli": {{Name: "brotli"}, {Name: "brotlicffi"}},
|
||||||
|
"http2": {{Name: "h2"}},
|
||||||
|
"cli": {{Name: "click"}, {Name: "rich"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// map iteration order is randomized, so check many runs rather than one
|
||||||
|
for i := 0; i < 50; i++ {
|
||||||
|
var names []string
|
||||||
|
for _, e := range extractUvExtras(p) {
|
||||||
|
names = append(names, e.Name)
|
||||||
|
}
|
||||||
|
assert.Equal(t, []string{"brotli", "cli", "http2", "socks"}, names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user