-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(license): using common way for splitting licenses (#4434)
* fix(license): using common way for splitting licenses * add test cases * TEST new regex * extract function * fix version detection --------- Co-authored-by: Nikita Pivkin <nikita.pivkin@smartforce.io>
- Loading branch information
Showing
4 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package licensing_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aquasecurity/trivy/pkg/licensing" | ||
) | ||
|
||
func TestSplitLicenses(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
license string | ||
licenses []string | ||
}{ | ||
{ | ||
"simple list comma-separated", | ||
"GPL-1+,GPL-2", | ||
[]string{"GPL-1+", "GPL-2"}, | ||
}, | ||
{ | ||
"simple list comma-separated", | ||
"GPL-1+,GPL-2,GPL-3", | ||
[]string{"GPL-1+", "GPL-2", "GPL-3"}, | ||
}, | ||
{ | ||
"3 licenses 'or'-separated", | ||
"GPL-1+ or Artistic or Artistic-dist", | ||
[]string{"GPL-1+", "Artistic", "Artistic-dist"}, | ||
}, | ||
// ' | ||
{ | ||
"two licenses _or_ separated", | ||
"LGPLv3+_or_GPLv2+", | ||
[]string{"LGPLv3+", "GPLv2+"}, | ||
}, | ||
// ' | ||
{ | ||
"licenses `and`-separated", | ||
"BSD-3-CLAUSE and GPL-2", | ||
[]string{"BSD-3-CLAUSE", "GPL-2"}, | ||
}, | ||
{ | ||
"three licenses and/or separated", | ||
"GPL-1+ or Artistic, and BSD-4-clause-POWERDOG", | ||
[]string{"GPL-1+", "Artistic", "BSD-4-clause-POWERDOG"}, | ||
}, | ||
{ | ||
"two licenses with version", | ||
"Apache License,Version 2.0, OSET Public License version 2.1", | ||
[]string{"Apache License, Version 2.0", "OSET Public License version 2.1"}, | ||
}, | ||
{ | ||
"the license starts with `ver`", | ||
"verbatim and BSD-4-clause", | ||
[]string{"verbatim", "BSD-4-clause"}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res := licensing.SplitLicenses(tt.license) | ||
assert.Equal(t, tt.licenses, res) | ||
}) | ||
} | ||
} |