github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/dart/parse_pubspec_test.go (about) 1 package dart 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/artifact" 7 "github.com/anchore/syft/syft/file" 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 10 ) 11 12 func TestParsePubspec(t *testing.T) { 13 tests := []struct { 14 name string 15 fixture string 16 expectedPackages []pkg.Package 17 expectedRelationships []artifact.Relationship 18 }{ 19 { 20 name: "_macros", 21 fixture: "test-fixtures/pubspecs/macros.pubspec.yaml", 22 expectedPackages: []pkg.Package{ 23 { 24 Name: "_macros", 25 Version: "0.3.2", 26 PURL: "pkg:pub/_macros@0.3.2", 27 Locations: file.NewLocationSet(file.NewLocation("test-fixtures/pubspecs/macros.pubspec.yaml")), 28 Language: pkg.Dart, 29 Type: pkg.DartPubPkg, 30 Metadata: pkg.DartPubspec{ 31 Repository: "https://github.com/dart-lang/sdk/tree/main/pkg/_macros", 32 PublishTo: "none", 33 Environment: &pkg.DartPubspecEnvironment{ 34 SDK: "^3.4.0-256.0.dev", 35 }, 36 }, 37 }, 38 }, 39 expectedRelationships: nil, 40 }, 41 { 42 name: "_macros", 43 fixture: "test-fixtures/pubspecs/appainter.pubspec.yaml", 44 expectedPackages: []pkg.Package{ 45 { 46 Name: "appainter", 47 Version: "2.4.8", 48 PURL: "pkg:pub/appainter@2.4.8", 49 Locations: file.NewLocationSet(file.NewLocation("test-fixtures/pubspecs/appainter.pubspec.yaml")), 50 Language: pkg.Dart, 51 Type: pkg.DartPubPkg, 52 Metadata: pkg.DartPubspec{ 53 PublishTo: "none", 54 Environment: &pkg.DartPubspecEnvironment{ 55 SDK: ">=3.0.0 <4.0.0", 56 Flutter: "3.29.3", 57 }, 58 }, 59 }, 60 }, 61 expectedRelationships: nil, 62 }, 63 } 64 65 for _, test := range tests { 66 t.Run(test.name, func(t *testing.T) { 67 pkgtest.TestFileParser(t, test.fixture, parsePubspec, test.expectedPackages, test.expectedRelationships) 68 }) 69 } 70 }