-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: inconsistent removal of binaries by overlap (#2036)
Signed-off-by: Keith Zantow <[email protected]>
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package syft | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
) | ||
|
||
func Test_removeRelationshipsByID(t *testing.T) { | ||
p1 := pkg.Package{} | ||
p1.OverrideID("1") | ||
|
||
p2 := pkg.Package{} | ||
p2.OverrideID("2") | ||
|
||
p3 := pkg.Package{} | ||
p3.OverrideID("3") | ||
|
||
rel := func(pkgs ...pkg.Package) (out []artifact.Relationship) { | ||
for _, p := range pkgs { | ||
out = append(out, artifact.Relationship{ | ||
From: p, | ||
To: p, | ||
Type: artifact.OwnershipByFileOverlapRelationship, | ||
}) | ||
} | ||
return | ||
} | ||
|
||
relationships := rel(p1, p2, p3) | ||
|
||
for _, r := range relationships { | ||
if r.From.ID() == "1" || r.From.ID() == "2" { | ||
relationships = removeRelationshipsByID(relationships, r.From.ID()) | ||
} | ||
} | ||
|
||
require.Equal(t, rel(p3), relationships) | ||
} |