github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/test/integration/sbom_cataloger_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/anchore/syft/syft/pkg"
     7  	"github.com/anchore/syft/syft/source"
     8  )
     9  
    10  func TestSbomCataloger(t *testing.T) {
    11  	// The image contains a go.mod file with 2 dependencies and an spdx json sbom.
    12  	// The go.mod file contains 2 dependencies, and the sbom includes a go dependency
    13  	// that overlaps with the go.mod
    14  	sbom, _ := catalogFixtureImage(t, "image-sbom-cataloger", source.SquashedScope, []string{"all"})
    15  
    16  	expectedSbomCatalogerPkgs := 1
    17  	expectedGoModCatalogerPkgs := 2
    18  	actualSbomPkgs := 0
    19  	actualGoModPkgs := 0
    20  	for pkg := range sbom.Artifacts.Packages.Enumerate(pkg.GoModulePkg) {
    21  		if pkg.FoundBy == "go-mod-file-cataloger" {
    22  			actualGoModPkgs += 1
    23  		} else if pkg.FoundBy == "sbom-cataloger" {
    24  			actualSbomPkgs += 1
    25  		}
    26  	}
    27  
    28  	if actualGoModPkgs != expectedGoModCatalogerPkgs {
    29  		t.Errorf("unexpected number of packages from go mod cataloger: %d != %d", expectedGoModCatalogerPkgs, actualGoModPkgs)
    30  	}
    31  	if actualSbomPkgs != expectedSbomCatalogerPkgs {
    32  		t.Errorf("unexpected number of packages from sbom cataloger: %d != %d", expectedSbomCatalogerPkgs, actualSbomPkgs)
    33  	}
    34  }