Skip to content

Commit

Permalink
test: deduplication updates
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
spiffcs committed Aug 7, 2023
1 parent 1a0df53 commit d45458e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
15 changes: 13 additions & 2 deletions syft/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,30 @@ func CatalogPackages(src source.Source, cfg cataloger.Config) (*pkg.Collection,

catalog, relationships, err := cataloger.Catalog(resolver, release, cfg.Parallelism, catalogers...)

relationships = append(relationships, newSourceRelationshipsFromCatalog(src, catalog)...)

// apply exclusions to the package catalog
// https://github.com/anchore/syft/issues/931
for _, r := range relationships {
if cataloger.Exclude(r, catalog) {
catalog.Delete(r.To.ID())
relationships = removeRelationshipsByID(relationships, r.To.ID())
}
}

// no need to consider source relationships for os -> binary exclusions
relationships = append(relationships, newSourceRelationshipsFromCatalog(src, catalog)...)
return catalog, relationships, release, err
}

func removeRelationshipsByID(relationships []artifact.Relationship, id artifact.ID) []artifact.Relationship {
filtered := make([]artifact.Relationship, 0)
for _, r := range relationships {
if r.To.ID() != id && r.From.ID() != id {
filtered = append(filtered, r)
}
}
return filtered
}

func newSourceRelationshipsFromCatalog(src source.Source, c *pkg.Collection) []artifact.Relationship {
relationships := make([]artifact.Relationship, 0) // Should we pre-allocate this by giving catalog a Len() method?
for p := range c.Enumerate() {
Expand Down
5 changes: 4 additions & 1 deletion test/integration/encode_decode_cycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import (
// encode-decode-encode loop which will detect lossy behavior in both directions.
func TestEncodeDecodeEncodeCycleComparison(t *testing.T) {
// use second image for relationships
images := []string{"image-pkg-coverage", "image-owning-package"}
images := []string{
//"image-pkg-coverage",
"image-owning-package",
}
tests := []struct {
formatOption sbom.FormatID
redactor func(in []byte) []byte
Expand Down
12 changes: 6 additions & 6 deletions test/integration/package_deduplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func TestPackageDeduplication(t *testing.T) {
}{
{
scope: source.AllLayersScope,
packageCount: 174, // without deduplication this would be 618
packageCount: 172, // without deduplication this would be 618
instanceCount: map[string]int{
"basesystem": 1,
"wget": 1,
"curl": 2, // upgraded in the image
"vsftpd": 1,
"httpd": 2, // rpm, binary
"httpd": 1, // rpm, - we exclude binary
},
locationCount: map[string]int{
"basesystem-10.0-7.el7.centos": 4,
Expand All @@ -37,26 +37,26 @@ func TestPackageDeduplication(t *testing.T) {
"wget-1.14-18.el7_6.1": 3,
"vsftpd-3.0.2-29.el7_9": 2,
"httpd-2.4.6-97.el7.centos.5": 1,
"httpd-2.4.6": 1, // binary
// "httpd-2.4.6": 1, // binary
},
},
{
scope: source.SquashedScope,
packageCount: 172,
packageCount: 170,
instanceCount: map[string]int{
"basesystem": 1,
"wget": 1,
"curl": 1, // upgraded, but the most recent
"vsftpd": 1,
"httpd": 2, // rpm, binary
"httpd": 1, // rpm, binary is now excluded by overlap
},
locationCount: map[string]int{
"basesystem-10.0-7.el7.centos": 1,
"curl-7.29.0-59.el7_9.1": 1, // upgrade
"wget-1.14-18.el7_6.1": 1,
"vsftpd-3.0.2-29.el7_9": 1,
"httpd-2.4.6-97.el7.centos.5": 1,
"httpd-2.4.6": 1, // binary
// "httpd-2.4.6": 1, // binary (excluded)
},
},
}
Expand Down

0 comments on commit d45458e

Please sign in to comment.