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

Require ordering of relationships when comparing parser output #2160

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ VERSION
/test/results
coverage.txt
*.log
test/integration/test-fixtures/**/go.sum
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep running into goland generating go.sums for these and we don't want them in the codebase


# probable archives
.images
Expand Down
5 changes: 5 additions & 0 deletions syft/pkg/cataloger/cpp/parse_conanlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ func TestParseConanlock(t *testing.T) {
},
}

// relationships require IDs to be set to be sorted similarly
for i := range expected {
expected[i].SetID()
}

var expectedRelationships = []artifact.Relationship{
{
From: expected[1], // boost
Expand Down
15 changes: 15 additions & 0 deletions syft/pkg/cataloger/internal/pkgtest/test_generic_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,28 @@ func (p *CatalogTester) TestCataloger(t *testing.T, cataloger pkg.Cataloger) {
}
}

func relationshipLess(x, y artifact.Relationship) bool {
xFrom := x.From.ID()
yFrom := y.From.ID()
if xFrom == yFrom {
xTo := x.To.ID()
yTo := y.To.ID()
if xTo == yTo {
return x.Type < y.Type
}
return xTo < yTo
}
return xFrom < yFrom
}

// nolint:funlen
func (p *CatalogTester) assertPkgs(t *testing.T, pkgs []pkg.Package, relationships []artifact.Relationship) {
t.Helper()

p.compareOptions = append(p.compareOptions,
cmpopts.IgnoreFields(pkg.Package{}, "id"), // note: ID is not deterministic for test purposes
cmpopts.SortSlices(pkg.Less),
cmpopts.SortSlices(relationshipLess),
cmp.Comparer(
func(x, y file.LocationSet) bool {
xs := x.ToSlice()
Expand Down
Loading