github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/debian/parse_copyright_test.go (about) 1 package debian 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 fixture: "test-fixtures/copyright/cuda", 40 expected: []string{"NVIDIA Software License Agreement and CUDA Supplement to Software License Agreement"}, 41 }, 42 { 43 fixture: "test-fixtures/copyright/dev-kit", 44 expected: []string{"LICENSE AGREEMENT FOR NVIDIA SOFTWARE DEVELOPMENT KITS"}, 45 }, 46 { 47 fixture: "test-fixtures/copyright/microsoft", 48 expected: []string{"LICENSE AGREEMENT FOR MICROSOFT PRODUCTS"}, 49 }, 50 } 51 52 for _, test := range tests { 53 t.Run(test.fixture, func(t *testing.T) { 54 f, err := os.Open(test.fixture) 55 require.NoError(t, err) 56 t.Cleanup(func() { require.NoError(t, f.Close()) }) 57 58 actual := parseLicensesFromCopyright(f) 59 60 if diff := cmp.Diff(test.expected, actual); diff != "" { 61 t.Errorf("unexpected package licenses (-want +got):\n%s", diff) 62 } 63 }) 64 } 65 }