github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/deb/parse_copyright_test.go (about) 1 package deb 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestParseLicensesFromCopyright(t *testing.T) { 12 tests := []struct { 13 fixture string 14 expected []string 15 }{ 16 { 17 fixture: "test-fixtures/copyright/libc6", 18 // note: there are other licenses in this file that are not matched --we don't do full text license identification yet 19 expected: []string{"GPL-2", "LGPL-2.1"}, 20 }, 21 { 22 fixture: "test-fixtures/copyright/trilicense", 23 expected: []string{"GPL-2", "LGPL-2.1", "MPL-1.1"}, 24 }, 25 { 26 fixture: "test-fixtures/copyright/liblzma5", 27 expected: []string{"Autoconf", "GPL-2", "GPL-2+", "GPL-3", "LGPL-2", "LGPL-2.1", "LGPL-2.1+", "PD", "PD-debian", "config-h", "noderivs", "permissive-fsf", "permissive-nowarranty", "probably-PD"}, 28 }, 29 { 30 fixture: "test-fixtures/copyright/libaudit-common", 31 expected: []string{"GPL-1", "GPL-2", "LGPL-2.1"}, 32 }, 33 { 34 fixture: "test-fixtures/copyright/python", 35 // note: this should not capture #, Permission, This, see ... however it's not clear how to fix this (this is probably good enough) 36 expected: []string{"#", "Apache", "Apache-2", "Apache-2.0", "Expat", "GPL-2", "ISC", "LGPL-2.1+", "PSF-2", "Permission", "Python", "This", "see"}, 37 }, 38 } 39 40 for _, test := range tests { 41 t.Run(test.fixture, func(t *testing.T) { 42 f, err := os.Open(test.fixture) 43 require.NoError(t, err) 44 t.Cleanup(func() { require.NoError(t, f.Close()) }) 45 46 actual := parseLicensesFromCopyright(f) 47 48 if diff := cmp.Diff(test.expected, actual); diff != "" { 49 t.Errorf("unexpected package licenses (-want +got):\n%s", diff) 50 } 51 }) 52 } 53 }