mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
chore: fix flaky license sorting (#1690)
Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
parent
168c5aed51
commit
11e926ab2f
@ -9,6 +9,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spdx/tools-golang/spdx"
|
"github.com/spdx/tools-golang/spdx"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal"
|
"github.com/anchore/syft/internal"
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
@ -521,8 +523,12 @@ func toOtherLicenses(catalog *pkg.Catalog) []*spdx.OtherLicense {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var result []*spdx.OtherLicense
|
var result []*spdx.OtherLicense
|
||||||
for license := range licenses {
|
|
||||||
|
sorted := maps.Keys(licenses)
|
||||||
|
slices.Sort(sorted)
|
||||||
|
for _, license := range sorted {
|
||||||
// separate the actual ID from the prefix
|
// separate the actual ID from the prefix
|
||||||
name := strings.TrimPrefix(license, spdxlicense.LicenseRefPrefix)
|
name := strings.TrimPrefix(license, spdxlicense.LicenseRefPrefix)
|
||||||
result = append(result, &spdx.OtherLicense{
|
result = append(result, &spdx.OtherLicense{
|
||||||
|
|||||||
@ -473,13 +473,13 @@ func Test_OtherLicenses(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: []*spdx.OtherLicense{
|
expected: []*spdx.OtherLicense{
|
||||||
{
|
{
|
||||||
LicenseIdentifier: "LicenseRef-un-known",
|
LicenseIdentifier: "LicenseRef-not-known--s",
|
||||||
LicenseName: "un known",
|
LicenseName: "not known %s",
|
||||||
ExtractedText: NONE,
|
ExtractedText: NONE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LicenseIdentifier: "LicenseRef-not-known--s",
|
LicenseIdentifier: "LicenseRef-un-known",
|
||||||
LicenseName: "not known %s",
|
LicenseName: "un known",
|
||||||
ExtractedText: NONE,
|
ExtractedText: NONE,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user