github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/arch/dependency_test.go (about) 1 package arch 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/anchore/syft/syft/pkg/cataloger/internal/dependency" 10 ) 11 12 func Test_dbEntryDependencySpecifier(t *testing.T) { 13 tests := []struct { 14 name string 15 p pkg.Package 16 want dependency.Specification 17 }{ 18 { 19 name: "keeps given values + package name", 20 p: pkg.Package{ 21 Name: "package-c", 22 Metadata: pkg.AlpmDBEntry{ 23 Provides: []string{"a-thing"}, 24 Depends: []string{"b-thing"}, 25 }, 26 }, 27 want: dependency.Specification{ 28 ProvidesRequires: dependency.ProvidesRequires{ 29 Provides: []string{"package-c", "a-thing", "a-thing"}, // note: gets deduplicated downstream 30 Requires: []string{"b-thing"}, 31 }, 32 }, 33 }, 34 { 35 name: "strip version specifiers", 36 p: pkg.Package{ 37 Name: "package-a", 38 Metadata: pkg.AlpmDBEntry{ 39 Provides: []string{"libtree-sitter.so.me=1-64"}, 40 Depends: []string{"libtree-sitter.so.thing=2-64"}, 41 }, 42 }, 43 want: dependency.Specification{ 44 ProvidesRequires: dependency.ProvidesRequires{ 45 Provides: []string{"package-a", "libtree-sitter.so.me=1-64", "libtree-sitter.so.me"}, 46 Requires: []string{"libtree-sitter.so.thing=2-64"}, 47 }, 48 }, 49 }, 50 { 51 name: "empty dependency data entries", 52 p: pkg.Package{ 53 Name: "package-a", 54 Metadata: pkg.AlpmDBEntry{ 55 Provides: []string{""}, 56 Depends: []string{""}, 57 }, 58 }, 59 want: dependency.Specification{ 60 ProvidesRequires: dependency.ProvidesRequires{ 61 Provides: []string{"package-a"}, 62 Requires: nil, 63 }, 64 }, 65 }, 66 } 67 for _, tt := range tests { 68 t.Run(tt.name, func(t *testing.T) { 69 assert.Equal(t, tt.want, dbEntryDependencySpecifier(tt.p)) 70 }) 71 } 72 } 73 74 func Test_stripVersionSpecifier(t *testing.T) { 75 tests := []struct { 76 name string 77 version string 78 want string 79 }{ 80 { 81 name: "empty expression", 82 version: "", 83 want: "", 84 }, 85 { 86 name: "no expression", 87 version: "gcc-libs", 88 want: "gcc-libs", 89 }, 90 { 91 name: "=", 92 version: "libtree-sitter.so=0-64", 93 want: "libtree-sitter.so", 94 }, 95 { 96 name: "ignores file paths", 97 version: "/bin/sh", 98 want: "/bin/sh", 99 }, 100 } 101 for _, tt := range tests { 102 t.Run(tt.name, func(t *testing.T) { 103 assert.Equal(t, tt.want, stripVersionSpecifier(tt.version)) 104 }) 105 } 106 }