github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/php/package_test.go (about) 1 package php 2 3 import ( 4 "testing" 5 6 "github.com/sergi/go-diff/diffmatchpatch" 7 ) 8 9 func Test_packageURL(t *testing.T) { 10 tests := []struct { 11 name string 12 packageName string 13 packageVersion string 14 expected string 15 }{ 16 { 17 name: "with extractable vendor", 18 packageName: "ven/name", 19 packageVersion: "1.0.1", 20 expected: "pkg:composer/ven/name@1.0.1", 21 }, 22 { 23 name: "name with slashes (invalid)", 24 packageName: "ven/name/component", 25 packageVersion: "1.0.1", 26 expected: "pkg:composer/ven/name-component@1.0.1", 27 }, 28 { 29 name: "unknown vendor", 30 packageName: "name", 31 packageVersion: "1.0.1", 32 expected: "pkg:composer/name@1.0.1", 33 }, 34 } 35 36 for _, test := range tests { 37 t.Run(test.name, func(t *testing.T) { 38 actual := packageURL(test.packageName, test.packageVersion) 39 if actual != test.expected { 40 dmp := diffmatchpatch.New() 41 diffs := dmp.DiffMain(test.expected, actual, true) 42 t.Errorf("diff: %s", dmp.DiffPrettyText(diffs)) 43 } 44 }) 45 } 46 } 47 48 func Test_packageURLFromPecl(t *testing.T) { 49 tests := []struct { 50 name string 51 version string 52 expected string 53 }{ 54 { 55 name: "memcached", 56 version: "3.2.0", 57 expected: "pkg:pecl/memcached@3.2.0", 58 }, 59 } 60 61 for _, test := range tests { 62 t.Run(test.name, func(t *testing.T) { 63 actual := packageURLFromPecl(test.name, test.version) 64 if actual != test.expected { 65 dmp := diffmatchpatch.New() 66 diffs := dmp.DiffMain(test.expected, actual, true) 67 t.Errorf("diff: %s", dmp.DiffPrettyText(diffs)) 68 } 69 }) 70 } 71 }