github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/swift/parse_package_resolved_test.go (about) 1 package swift 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 10 "github.com/anchore/syft/syft/artifact" 11 "github.com/anchore/syft/syft/file" 12 "github.com/anchore/syft/syft/pkg" 13 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 14 ) 15 16 func TestParsePackageResolved(t *testing.T) { 17 fixture := "test-fixtures/Package.resolved" 18 locations := file.NewLocationSet(file.NewLocation(fixture)) 19 expectedPkgs := []pkg.Package{ 20 { 21 Name: "swift-algorithms", 22 Version: "1.0.0", 23 PURL: "pkg:swift/github.com/apple/swift-algorithms.git/swift-algorithms@1.0.0", 24 Locations: locations, 25 Language: pkg.Swift, 26 Type: pkg.SwiftPkg, 27 Metadata: pkg.SwiftPackageManagerResolvedEntry{ 28 Revision: "b14b7f4c528c942f121c8b860b9410b2bf57825e", 29 }, 30 }, 31 { 32 Name: "swift-async-algorithms", 33 Version: "0.1.0", 34 PURL: "pkg:swift/github.com/apple/swift-async-algorithms.git/swift-async-algorithms@0.1.0", 35 Locations: locations, 36 Language: pkg.Swift, 37 Type: pkg.SwiftPkg, 38 Metadata: pkg.SwiftPackageManagerResolvedEntry{ 39 Revision: "9cfed92b026c524674ed869a4ff2dcfdeedf8a2a", 40 }, 41 }, 42 { 43 Name: "swift-atomics", 44 Version: "1.1.0", 45 PURL: "pkg:swift/github.com/apple/swift-atomics.git/swift-atomics@1.1.0", 46 Locations: locations, 47 Language: pkg.Swift, 48 Type: pkg.SwiftPkg, 49 Metadata: pkg.SwiftPackageManagerResolvedEntry{ 50 Revision: "6c89474e62719ddcc1e9614989fff2f68208fe10", 51 }, 52 }, 53 { 54 Name: "swift-collections", 55 Version: "1.0.4", 56 PURL: "pkg:swift/github.com/apple/swift-collections.git/swift-collections@1.0.4", 57 Locations: locations, 58 Language: pkg.Swift, 59 Type: pkg.SwiftPkg, 60 Metadata: pkg.SwiftPackageManagerResolvedEntry{ 61 Revision: "937e904258d22af6e447a0b72c0bc67583ef64a2", 62 }, 63 }, 64 { 65 Name: "swift-numerics", 66 Version: "1.0.2", 67 PURL: "pkg:swift/github.com/apple/swift-numerics/swift-numerics@1.0.2", 68 Locations: locations, 69 Language: pkg.Swift, 70 Type: pkg.SwiftPkg, 71 Metadata: pkg.SwiftPackageManagerResolvedEntry{ 72 Revision: "0a5bc04095a675662cf24757cc0640aa2204253b", 73 }, 74 }, 75 } 76 77 // TODO: no relationships are under test yet 78 var expectedRelationships []artifact.Relationship 79 80 pkgtest.TestFileParser(t, fixture, parsePackageResolved, expectedPkgs, expectedRelationships) 81 } 82 83 func TestParsePackageResolved_empty(t *testing.T) { 84 // regression for https://github.com/anchore/syft/issues/2225 85 fixture := "test-fixtures/empty-packages.resolved" 86 87 pkgtest.TestFileParser(t, fixture, parsePackageResolved, nil, nil) 88 89 dir := t.TempDir() 90 fixture = filepath.Join(dir, "Package.resolved") 91 _, err := os.Create(fixture) 92 require.NoError(t, err) 93 94 pkgtest.TestFileParser(t, fixture, parsePackageResolved, nil, nil) 95 } 96 97 func TestParsePackageResolved_versionNotANumber(t *testing.T) { 98 // regression for https://github.com/anchore/syft/issues/2225 99 fixture := "test-fixtures/bad-version-packages.resolved" 100 101 pkgtest.NewCatalogTester().FromFile(t, fixture).WithError().TestParser(t, parsePackageResolved) 102 }