fix: reset merged package into map; (#1258)

This commit is contained in:
Christopher Angelo Phillips 2022-10-11 14:35:46 -04:00 committed by GitHub
parent 780e1c310c
commit fa0b3c0438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -110,6 +110,7 @@ func (c *Catalog) Add(p Package) {
if err := existing.merge(p); err != nil { if err := existing.merge(p); err != nil {
log.Warnf("failed to merge packages: %+v", err) log.Warnf("failed to merge packages: %+v", err)
} else { } else {
c.byID[id] = existing
c.addPathsToIndex(p) c.addPathsToIndex(p)
} }
return return

View File

@ -70,9 +70,7 @@ func TestCatalogAddPopulatesIndex(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
c := NewCatalog(pkgs...) c := NewCatalog(pkgs...)
assertIndexes(t, c, test.expectedIndexes) assertIndexes(t, c, test.expectedIndexes)
}) })
} }
} }
@ -178,11 +176,13 @@ func TestCatalog_MergeRecords(t *testing.T) {
name string name string
pkgs []Package pkgs []Package
expectedLocations []source.Location expectedLocations []source.Location
expectedCPECount int
}{ }{
{ {
name: "multiple Locations with shared path", name: "multiple Locations with shared path",
pkgs: []Package{ pkgs: []Package{
{ {
CPEs: []CPE{MustCPE("cpe:2.3:a:package:1:1:*:*:*:*:*:*:*")},
Locations: source.NewLocationSet( Locations: source.NewLocationSet(
source.Location{ source.Location{
Coordinates: source.Coordinates{ Coordinates: source.Coordinates{
@ -195,6 +195,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
Type: RpmPkg, Type: RpmPkg,
}, },
{ {
CPEs: []CPE{MustCPE("cpe:2.3:b:package:1:1:*:*:*:*:*:*:*")},
Locations: source.NewLocationSet( Locations: source.NewLocationSet(
source.Location{ source.Location{
Coordinates: source.Coordinates{ Coordinates: source.Coordinates{
@ -223,6 +224,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
VirtualPath: "/another/path", VirtualPath: "/another/path",
}, },
}, },
expectedCPECount: 2,
}, },
} }
@ -231,6 +233,7 @@ func TestCatalog_MergeRecords(t *testing.T) {
actual := NewCatalog(tt.pkgs...).PackagesByPath("/b/path") actual := NewCatalog(tt.pkgs...).PackagesByPath("/b/path")
require.Len(t, actual, 1) require.Len(t, actual, 1)
assert.Equal(t, tt.expectedLocations, actual[0].Locations.ToSlice()) assert.Equal(t, tt.expectedLocations, actual[0].Locations.ToSlice())
require.Len(t, actual[0].CPEs, tt.expectedCPECount)
}) })
} }
} }