mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 07:26:34 +01:00
Use values in relationship To/From fields (#2871)
* use pkg values in relationship fields Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add linter rule for using values in relationships Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * use new cmptest package for comparing relationships Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * create cmptest for common cmp.Diff options in test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * condense matches for relationship ruleguard Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove relationship type from rules Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * restore build tag Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * suggest using values Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * nil check pkgs Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -58,9 +58,19 @@ func byFileOwnershipOverlap(catalog *pkg.Collection) []artifact.Relationship {
|
||||
parent := catalog.Package(parentID) // TODO: this is potentially expensive
|
||||
child := catalog.Package(childID) // TODO: this is potentially expensive
|
||||
|
||||
if parent == nil {
|
||||
log.Tracef("parent package not found: %v", parentID)
|
||||
continue
|
||||
}
|
||||
|
||||
if child == nil {
|
||||
log.Tracef("child package not found: %v", childID)
|
||||
continue
|
||||
}
|
||||
|
||||
edges = append(edges, artifact.Relationship{
|
||||
From: parent,
|
||||
To: child,
|
||||
From: *parent,
|
||||
To: *child,
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
Data: ownershipByFilesMetadata{
|
||||
Files: fs,
|
||||
|
||||
@@ -3,8 +3,10 @@ package relationship
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/anchore/syft/internal/cmptest"
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
@@ -143,10 +145,9 @@ func TestOwnershipByFilesRelationship(t *testing.T) {
|
||||
assert.Len(t, relationships, len(expectedRelations))
|
||||
for idx, expectedRelationship := range expectedRelations {
|
||||
actualRelationship := relationships[idx]
|
||||
assert.Equal(t, expectedRelationship.From.ID(), actualRelationship.From.ID())
|
||||
assert.Equal(t, expectedRelationship.To.ID(), actualRelationship.To.ID())
|
||||
assert.Equal(t, expectedRelationship.Type, actualRelationship.Type)
|
||||
assert.Equal(t, expectedRelationship.Data, actualRelationship.Data)
|
||||
if d := cmp.Diff(expectedRelationship, actualRelationship, cmptest.DefaultCommonOptions()...); d != "" {
|
||||
t.Errorf("unexpected relationship (-want, +got): %s", d)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user