mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Co-authored-by: Dan Luhring <luhring@users.noreply.github.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package deb
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/go-test/deep"
|
|
)
|
|
|
|
func TestParseLicensesFromCopyright(t *testing.T) {
|
|
tests := []struct {
|
|
fixture string
|
|
expected []string
|
|
}{
|
|
{
|
|
fixture: "test-fixtures/copyright/trilicense",
|
|
expected: []string{"GPL-2", "LGPL-2.1", "MPL-1.1"},
|
|
},
|
|
{
|
|
fixture: "test-fixtures/copyright/liblzma5",
|
|
expected: []string{"Autoconf", "GPL-2", "GPL-2+", "LGPL-2.1+", "PD", "PD-debian", "config-h", "noderivs", "permissive-fsf", "permissive-nowarranty", "probably-PD"},
|
|
},
|
|
{
|
|
fixture: "test-fixtures/copyright/libaudit-common",
|
|
expected: []string{"GPL-2", "LGPL-2.1"},
|
|
},
|
|
{
|
|
fixture: "test-fixtures/copyright/python",
|
|
// note: this should not capture #, Permission, This, see ... however it's not clear how to fix this (this is probably good enough)
|
|
expected: []string{"#", "Apache", "Apache-2", "Apache-2.0", "Expat", "ISC", "LGPL-2.1+", "PSF-2", "Permission", "Python", "This", "see"},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.fixture, func(t *testing.T) {
|
|
file, err := os.Open(test.fixture)
|
|
if err != nil {
|
|
t.Fatal("Unable to read: ", err)
|
|
}
|
|
defer func() {
|
|
err := file.Close()
|
|
if err != nil {
|
|
t.Fatal("closing file failed:", err)
|
|
}
|
|
}()
|
|
|
|
actual := parseLicensesFromCopyright(file)
|
|
|
|
if len(actual) != len(test.expected) {
|
|
for _, a := range actual {
|
|
t.Logf(" %+v", a)
|
|
}
|
|
t.Fatalf("unexpected package count: %d!=%d", len(actual), len(test.expected))
|
|
}
|
|
|
|
diffs := deep.Equal(actual, test.expected)
|
|
for _, d := range diffs {
|
|
t.Errorf("diff: %+v", d)
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|