github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/pkg/cataloger/rust/cataloger_test.go (about)

     1  package rust
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/file"
     7  	"github.com/anchore/syft/syft/pkg"
     8  	"github.com/lineaje-labs/syft/syft/pkg/cataloger/internal/pkgtest"
     9  )
    10  
    11  func TestNewAuditBinaryCataloger(t *testing.T) {
    12  
    13  	expectedPkgs := []pkg.Package{
    14  		{
    15  			Name:      "auditable",
    16  			Version:   "0.1.0",
    17  			PURL:      "pkg:cargo/auditable@0.1.0",
    18  			FoundBy:   "cargo-auditable-binary-cataloger",
    19  			Locations: file.NewLocationSet(file.NewVirtualLocation("/hello-auditable", "/hello-auditable")),
    20  			Language:  pkg.Rust,
    21  			Type:      pkg.RustPkg,
    22  			Metadata: pkg.RustBinaryAuditEntry{
    23  				Name:    "auditable",
    24  				Version: "0.1.0",
    25  				Source:  "local",
    26  			},
    27  		},
    28  		{
    29  			Name:      "hello-auditable",
    30  			Version:   "0.1.0",
    31  			PURL:      "pkg:cargo/hello-auditable@0.1.0",
    32  			FoundBy:   "cargo-auditable-binary-cataloger",
    33  			Locations: file.NewLocationSet(file.NewVirtualLocation("/hello-auditable", "/hello-auditable")),
    34  			Language:  pkg.Rust,
    35  			Type:      pkg.RustPkg,
    36  			Metadata: pkg.RustBinaryAuditEntry{
    37  				Name:    "hello-auditable",
    38  				Version: "0.1.0",
    39  				Source:  "local",
    40  			},
    41  		},
    42  	}
    43  
    44  	pkgtest.NewCatalogTester().
    45  		WithImageResolver(t, "image-audit").
    46  		IgnoreLocationLayer(). // this fixture can be rebuilt, thus the layer ID will change
    47  		Expects(expectedPkgs, nil).
    48  		TestCataloger(t, NewAuditBinaryCataloger())
    49  }
    50  
    51  func Test_CargoLockCataloger_Globs(t *testing.T) {
    52  	tests := []struct {
    53  		name     string
    54  		fixture  string
    55  		expected []string
    56  	}{
    57  		{
    58  			name:    "obtain Cargo.lock files",
    59  			fixture: "test-fixtures/glob-paths",
    60  			expected: []string{
    61  				"src/Cargo.lock",
    62  			},
    63  		},
    64  	}
    65  
    66  	for _, test := range tests {
    67  		t.Run(test.name, func(t *testing.T) {
    68  			pkgtest.NewCatalogTester().
    69  				FromDirectory(t, test.fixture).
    70  				ExpectsResolverContentQueries(test.expected).
    71  				TestCataloger(t, NewCargoLockCataloger())
    72  		})
    73  	}
    74  }
    75  
    76  func Test_AuditBinaryCataloger_Globs(t *testing.T) {
    77  	tests := []struct {
    78  		name     string
    79  		fixture  string
    80  		expected []string
    81  	}{
    82  		{
    83  			name:    "obtain audit binary files",
    84  			fixture: "test-fixtures/glob-paths",
    85  			expected: []string{
    86  				"partial-binary",
    87  			},
    88  		},
    89  	}
    90  
    91  	for _, test := range tests {
    92  		t.Run(test.name, func(t *testing.T) {
    93  			pkgtest.NewCatalogTester().
    94  				FromDirectory(t, test.fixture).
    95  				ExpectsResolverContentQueries(test.expected).
    96  				TestCataloger(t, NewAuditBinaryCataloger())
    97  		})
    98  	}
    99  }