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