Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset merged package into map; #1258

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions syft/pkg/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (c *Catalog) Add(p Package) {
if err := existing.merge(p); err != nil {
log.Warnf("failed to merge packages: %+v", err)
} else {
c.byID[id] = existing
c.addPathsToIndex(p)
}
return
Expand Down
7 changes: 5 additions & 2 deletions syft/pkg/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func TestCatalogAddPopulatesIndex(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
c := NewCatalog(pkgs...)

assertIndexes(t, c, test.expectedIndexes)

})
}
}
Expand Down Expand Up @@ -178,11 +176,13 @@ func TestCatalog_MergeRecords(t *testing.T) {
name string
pkgs []Package
expectedLocations []source.Location
expectedCPECount int
}{
{
name: "multiple Locations with shared path",
pkgs: []Package{
{
CPEs: []CPE{MustCPE("cpe:2.3:a:package:1:1:*:*:*:*:*:*:*")},
Locations: source.NewLocationSet(
source.Location{
Coordinates: source.Coordinates{
Expand All @@ -195,6 +195,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
Type: RpmPkg,
},
{
CPEs: []CPE{MustCPE("cpe:2.3:b:package:1:1:*:*:*:*:*:*:*")},
Locations: source.NewLocationSet(
source.Location{
Coordinates: source.Coordinates{
Expand Down Expand Up @@ -223,6 +224,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
VirtualPath: "/another/path",
},
},
expectedCPECount: 2,
},
}

Expand All @@ -231,6 +233,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
actual := NewCatalog(tt.pkgs...).PackagesByPath("/b/path")
require.Len(t, actual, 1)
assert.Equal(t, tt.expectedLocations, actual[0].Locations.ToSlice())
require.Len(t, actual[0].CPEs, tt.expectedCPECount)
})
}
}
Expand Down