mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 02:26:42 +01:00
chore: update license sort to be stable with contents field (#3860)
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
parent
7b25ea5eda
commit
6eff158ad3
5
internal/licenses/test-fixtures/Knuth-CTAN
Normal file
5
internal/licenses/test-fixtures/Knuth-CTAN
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Knuth CTAN License
|
||||||
|
Full name
|
||||||
|
Knuth CTAN License
|
||||||
|
|
||||||
|
This software is copyrighted. Unlimited copying and redistribution of this package and/or its individual files are permitted as long as there are no modifications. Modifications, and redistribution of modifications, are also permitted, but only if the resulting package and/or files are renamed.
|
||||||
@ -49,6 +49,7 @@ func (l Licenses) Less(i, j int) bool {
|
|||||||
if l[i].Value == l[j].Value {
|
if l[i].Value == l[j].Value {
|
||||||
if l[i].SPDXExpression == l[j].SPDXExpression {
|
if l[i].SPDXExpression == l[j].SPDXExpression {
|
||||||
if l[i].Type == l[j].Type {
|
if l[i].Type == l[j].Type {
|
||||||
|
if l[i].Contents == l[j].Contents {
|
||||||
// While URLs and location are not exclusive fields
|
// While URLs and location are not exclusive fields
|
||||||
// returning true here reduces the number of swaps
|
// returning true here reduces the number of swaps
|
||||||
// while keeping a consistent sort order of
|
// while keeping a consistent sort order of
|
||||||
@ -57,6 +58,8 @@ func (l Licenses) Less(i, j int) bool {
|
|||||||
// on the slice representation of either field we can update this code
|
// on the slice representation of either field we can update this code
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
return l[i].Contents < l[j].Contents
|
||||||
|
}
|
||||||
return l[i].Type < l[j].Type
|
return l[i].Type < l[j].Type
|
||||||
}
|
}
|
||||||
return l[i].SPDXExpression < l[j].SPDXExpression
|
return l[i].SPDXExpression < l[j].SPDXExpression
|
||||||
|
|||||||
@ -84,6 +84,19 @@ func Test_Sort(t *testing.T) {
|
|||||||
NewLicenseFromLocations("MIT", file.NewLocation("place!")),
|
NewLicenseFromLocations("MIT", file.NewLocation("place!")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "multiple licenses with only contents",
|
||||||
|
licenses: []License{
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/nvidia-software-and-cuda-supplement")),
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/Knuth-CTAN")),
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/apache-license-2.0")),
|
||||||
|
},
|
||||||
|
expected: Licenses{
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/apache-license-2.0")),
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/nvidia-software-and-cuda-supplement")),
|
||||||
|
NewLicense(readFileAsString("../../internal/licenses/test-fixtures/Knuth-CTAN")),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user