github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/rust/parse_cargo_lock_test.go (about)

     1  package rust
     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 TestParseCargoLock(t *testing.T) {
    13  	fixture := "test-fixtures/Cargo.lock"
    14  	locations := file.NewLocationSet(file.NewLocation(fixture))
    15  	expectedPkgs := []pkg.Package{
    16  		{
    17  			Name:         "ansi_term",
    18  			Version:      "0.12.1",
    19  			PURL:         "pkg:cargo/ansi_term@0.12.1",
    20  			Locations:    locations,
    21  			Language:     pkg.Rust,
    22  			Type:         pkg.RustPkg,
    23  			MetadataType: pkg.RustCargoPackageMetadataType,
    24  			Licenses:     pkg.NewLicenseSet(),
    25  			Metadata: pkg.CargoPackageMetadata{
    26  				Name:     "ansi_term",
    27  				Version:  "0.12.1",
    28  				Source:   "registry+https://github.com/rust-lang/crates.io-index",
    29  				Checksum: "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2",
    30  				Dependencies: []string{
    31  					"winapi",
    32  				},
    33  			},
    34  		},
    35  		{
    36  			Name:         "matches",
    37  			Version:      "0.1.8",
    38  			PURL:         "pkg:cargo/matches@0.1.8",
    39  			Locations:    locations,
    40  			Language:     pkg.Rust,
    41  			Type:         pkg.RustPkg,
    42  			MetadataType: pkg.RustCargoPackageMetadataType,
    43  			Licenses:     pkg.NewLicenseSet(),
    44  			Metadata: pkg.CargoPackageMetadata{
    45  				Name:         "matches",
    46  				Version:      "0.1.8",
    47  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
    48  				Checksum:     "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08",
    49  				Dependencies: []string{},
    50  			},
    51  		},
    52  		{
    53  			Name:         "memchr",
    54  			Version:      "2.3.3",
    55  			PURL:         "pkg:cargo/memchr@2.3.3",
    56  			Locations:    locations,
    57  			Language:     pkg.Rust,
    58  			Type:         pkg.RustPkg,
    59  			MetadataType: pkg.RustCargoPackageMetadataType,
    60  			Licenses:     pkg.NewLicenseSet(),
    61  			Metadata: pkg.CargoPackageMetadata{
    62  				Name:         "memchr",
    63  				Version:      "2.3.3",
    64  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
    65  				Checksum:     "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400",
    66  				Dependencies: []string{},
    67  			},
    68  		},
    69  		{
    70  			Name:         "natord",
    71  			Version:      "1.0.9",
    72  			PURL:         "pkg:cargo/natord@1.0.9",
    73  			Locations:    locations,
    74  			Language:     pkg.Rust,
    75  			Type:         pkg.RustPkg,
    76  			MetadataType: pkg.RustCargoPackageMetadataType,
    77  			Licenses:     pkg.NewLicenseSet(),
    78  			Metadata: pkg.CargoPackageMetadata{
    79  				Name:         "natord",
    80  				Version:      "1.0.9",
    81  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
    82  				Checksum:     "308d96db8debc727c3fd9744aac51751243420e46edf401010908da7f8d5e57c",
    83  				Dependencies: []string{},
    84  			},
    85  		},
    86  		{
    87  			Name:         "nom",
    88  			Version:      "4.2.3",
    89  			PURL:         "pkg:cargo/nom@4.2.3",
    90  			Locations:    locations,
    91  			Language:     pkg.Rust,
    92  			Type:         pkg.RustPkg,
    93  			MetadataType: pkg.RustCargoPackageMetadataType,
    94  			Licenses:     pkg.NewLicenseSet(),
    95  			Metadata: pkg.CargoPackageMetadata{
    96  				Name:     "nom",
    97  				Version:  "4.2.3",
    98  				Source:   "registry+https://github.com/rust-lang/crates.io-index",
    99  				Checksum: "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6",
   100  				Dependencies: []string{
   101  					"memchr",
   102  					"version_check",
   103  				},
   104  			},
   105  		},
   106  		{
   107  			Name:         "unicode-bidi",
   108  			Version:      "0.3.4",
   109  			PURL:         "pkg:cargo/unicode-bidi@0.3.4",
   110  			Locations:    locations,
   111  			Language:     pkg.Rust,
   112  			Type:         pkg.RustPkg,
   113  			MetadataType: pkg.RustCargoPackageMetadataType,
   114  			Licenses:     pkg.NewLicenseSet(),
   115  			Metadata: pkg.CargoPackageMetadata{
   116  				Name:     "unicode-bidi",
   117  				Version:  "0.3.4",
   118  				Source:   "registry+https://github.com/rust-lang/crates.io-index",
   119  				Checksum: "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5",
   120  				Dependencies: []string{
   121  					"matches",
   122  				},
   123  			},
   124  		},
   125  		{
   126  			Name:         "version_check",
   127  			Version:      "0.1.5",
   128  			PURL:         "pkg:cargo/version_check@0.1.5",
   129  			Locations:    locations,
   130  			Language:     pkg.Rust,
   131  			Type:         pkg.RustPkg,
   132  			MetadataType: pkg.RustCargoPackageMetadataType,
   133  			Licenses:     pkg.NewLicenseSet(),
   134  			Metadata: pkg.CargoPackageMetadata{
   135  				Name:         "version_check",
   136  				Version:      "0.1.5",
   137  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
   138  				Checksum:     "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd",
   139  				Dependencies: []string{},
   140  			},
   141  		},
   142  		{
   143  			Name:         "winapi",
   144  			Version:      "0.3.9",
   145  			PURL:         "pkg:cargo/winapi@0.3.9",
   146  			Locations:    locations,
   147  			Language:     pkg.Rust,
   148  			Type:         pkg.RustPkg,
   149  			MetadataType: pkg.RustCargoPackageMetadataType,
   150  			Licenses:     pkg.NewLicenseSet(),
   151  			Metadata: pkg.CargoPackageMetadata{
   152  				Name:     "winapi",
   153  				Version:  "0.3.9",
   154  				Source:   "registry+https://github.com/rust-lang/crates.io-index",
   155  				Checksum: "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419",
   156  				Dependencies: []string{
   157  					"winapi-i686-pc-windows-gnu",
   158  					"winapi-x86_64-pc-windows-gnu",
   159  				},
   160  			},
   161  		},
   162  		{
   163  			Name:         "winapi-i686-pc-windows-gnu",
   164  			Version:      "0.4.0",
   165  			PURL:         "pkg:cargo/winapi-i686-pc-windows-gnu@0.4.0",
   166  			Locations:    locations,
   167  			Language:     pkg.Rust,
   168  			Type:         pkg.RustPkg,
   169  			MetadataType: pkg.RustCargoPackageMetadataType,
   170  			Licenses:     pkg.NewLicenseSet(),
   171  			Metadata: pkg.CargoPackageMetadata{
   172  				Name:         "winapi-i686-pc-windows-gnu",
   173  				Version:      "0.4.0",
   174  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
   175  				Checksum:     "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6",
   176  				Dependencies: []string{},
   177  			},
   178  		},
   179  		{
   180  			Name:         "winapi-x86_64-pc-windows-gnu",
   181  			Version:      "0.4.0",
   182  			PURL:         "pkg:cargo/winapi-x86_64-pc-windows-gnu@0.4.0",
   183  			Locations:    locations,
   184  			Language:     pkg.Rust,
   185  			Type:         pkg.RustPkg,
   186  			MetadataType: pkg.RustCargoPackageMetadataType,
   187  			Licenses:     pkg.NewLicenseSet(),
   188  			Metadata: pkg.CargoPackageMetadata{
   189  				Name:         "winapi-x86_64-pc-windows-gnu",
   190  				Version:      "0.4.0",
   191  				Source:       "registry+https://github.com/rust-lang/crates.io-index",
   192  				Checksum:     "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f",
   193  				Dependencies: []string{},
   194  			},
   195  		},
   196  	}
   197  
   198  	// TODO: no relationships are under test yet
   199  	var expectedRelationships []artifact.Relationship
   200  
   201  	pkgtest.TestFileParser(t, fixture, parseCargoLock, expectedPkgs, expectedRelationships)
   202  
   203  }