github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/binary/elf_package_cataloger_test.go (about)

     1  package binary
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/file"
     7  	"github.com/anchore/syft/syft/pkg"
     8  	"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
     9  )
    10  
    11  func Test_ELF_Package_Cataloger(t *testing.T) {
    12  	expectedPkgs := []pkg.Package{
    13  		{
    14  			Name:    "libhello_world.so",
    15  			Version: "0.01",
    16  			PURL:    "pkg:generic/syftsys/libhello_world.so@0.01",
    17  			FoundBy: "",
    18  			Locations: file.NewLocationSet(
    19  				file.NewVirtualLocation("/usr/local/bin/elftests/elfbinwithnestedlib/bin/lib/libhello_world.so", "/usr/local/bin/elftests/elfbinwithnestedlib/bin/lib/libhello_world.so"),
    20  				file.NewVirtualLocation("/usr/local/bin/elftests/elfbinwithsisterlib/lib/libhello_world.so", "/usr/local/bin/elftests/elfbinwithsisterlib/lib/libhello_world.so"),
    21  				file.NewVirtualLocation("/usr/local/bin/elftests/elfbinwithsisterlib/lib/libhello_world2.so", "/usr/local/bin/elftests/elfbinwithsisterlib/lib/libhello_world2.so"),
    22  			),
    23  			Language: "",
    24  			Type:     pkg.BinaryPkg,
    25  			Metadata: pkg.ELFBinaryPackageNoteJSONPayload{
    26  				Type:       "testfixture",
    27  				Vendor:     "syft",
    28  				System:     "syftsys",
    29  				SourceRepo: "https://github.com/someone/somewhere.git",
    30  				Commit:     "5534c38d0ffef9a3f83154f0b7a7fb6ab0ab6dbb",
    31  			},
    32  		},
    33  		{
    34  			Name:    "syfttestfixture",
    35  			Version: "0.01",
    36  			PURL:    "pkg:generic/syftsys/syfttestfixture@0.01",
    37  			FoundBy: "",
    38  			Locations: file.NewLocationSet(
    39  				file.NewLocation("/usr/local/bin/elftests/elfbinwithnestedlib/bin/elfbinwithnestedlib").WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
    40  				file.NewLocation("/usr/local/bin/elftests/elfbinwithsisterlib/bin/elfwithparallellibbin1").WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
    41  				file.NewLocation("/usr/local/bin/elftests/elfbinwithsisterlib/bin/elfwithparallellibbin2").WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
    42  			),
    43  			Language: "",
    44  			Type:     pkg.BinaryPkg,
    45  			Metadata: pkg.ELFBinaryPackageNoteJSONPayload{
    46  				Type:       "testfixture",
    47  				Vendor:     "syft",
    48  				System:     "syftsys",
    49  				SourceRepo: "https://github.com/someone/somewhere.git",
    50  				Commit:     "5534c38d0ffef9a3f83154f0b7a7fb6ab0ab6dbb",
    51  			},
    52  		},
    53  	}
    54  
    55  	pkgtest.NewCatalogTester().
    56  		WithImageResolver(t, "elf-test-fixtures").
    57  		IgnoreLocationLayer(). // this fixture can be rebuilt, thus the layer ID will change
    58  		Expects(expectedPkgs, nil).
    59  		TestCataloger(t, NewELFPackageCataloger())
    60  
    61  }