-
Keith Zantow committed with GitHub 1 year ago1 parent 096d2b7b
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
-
-
-
-
skipped 3 lines 4 4 "errors" 5 5 "fmt" 6 6 "io" 7 + "strings" 7 8 "testing" 8 9 10 + "github.com/google/go-cmp/cmp" 11 + "github.com/google/go-cmp/cmp/cmpopts" 9 12 "github.com/stretchr/testify/assert" 10 13 "github.com/stretchr/testify/require" 11 14 skipped 54 lines 66 69 PURL: "pkg:generic/[email protected]", 67 70 Locations: locations("postgres"), 68 71 Metadata: metadata("postgresql-binary"), 69 - }, 70 - }, 71 - { 72 - name: "positive-python-duplicates", 73 - fixtureDir: "test-fixtures/classifiers/positive/python-duplicates", 74 - expected: pkg.Package{ 75 - Name: "python", 76 - Version: "3.8.16", 77 - Type: "binary", 78 - PURL: "pkg:generic/[email protected]", 79 - Locations: locations("dir/python3.8", "python3.8", "libpython3.8.so", "patchlevel.h"), 80 - Metadata: pkg.BinaryMetadata{ 81 - Matches: []pkg.ClassifierMatch{ 82 - match("python-binary", "dir/python3.8"), 83 - match("python-binary", "python3.8"), 84 - match("python-binary-lib", "libpython3.8.so"), 85 - match("cpython-source", "patchlevel.h"), 86 - }, 87 - }, 88 72 }, 89 73 }, 90 74 { skipped 224 lines 315 299 }, 316 300 }, 317 301 { 302 + name: "positive-python-3.11.2-from-shared-lib", 303 + fixtureDir: "test-fixtures/classifiers/dynamic/python-binary-shared-lib-3.11", 304 + expected: pkg.Package{ 305 + Name: "python", 306 + Version: "3.11.2", 307 + PURL: "pkg:generic/[email protected]", 308 + Locations: locations("python3", "libpython3.11.so.1.0"), 309 + Metadata: pkg.BinaryMetadata{ 310 + Matches: []pkg.ClassifierMatch{ 311 + match("python-binary", "python3"), 312 + match("python-binary", "libpython3.11.so.1.0"), 313 + match("python-binary-lib", "libpython3.11.so.1.0"), 314 + }, 315 + }, 316 + }, 317 + }, 318 + { 319 + name: "positive-python-3.9-from-shared-redhat-lib", 320 + fixtureDir: "test-fixtures/classifiers/dynamic/python-binary-shared-lib-redhat-3.9", 321 + expected: pkg.Package{ 322 + Name: "python", 323 + Version: "3.9.13", 324 + PURL: "pkg:generic/[email protected]", 325 + Locations: locations("python3.9", "libpython3.9.so.1.0"), 326 + Metadata: pkg.BinaryMetadata{ 327 + Matches: []pkg.ClassifierMatch{ 328 + match("python-binary", "python3.9"), 329 + match("python-binary", "libpython3.9.so.1.0"), 330 + match("python-binary-lib", "libpython3.9.so.1.0"), 331 + }, 332 + }, 333 + }, 334 + }, 335 + { 336 + name: "positive-python-binary-with-version-3.9", 337 + fixtureDir: "test-fixtures/classifiers/dynamic/python-binary-with-version-3.9", 338 + expected: pkg.Package{ 339 + Name: "python", 340 + Version: "3.9.2", 341 + PURL: "pkg:generic/[email protected]", 342 + Locations: locations("python3.9"), 343 + Metadata: pkg.BinaryMetadata{ 344 + Matches: []pkg.ClassifierMatch{ 345 + match("python-binary", "python3.9"), 346 + }, 347 + }, 348 + }, 349 + }, 350 + { 318 351 name: "positive-python3.6", 319 352 fixtureDir: "test-fixtures/classifiers/positive/python-binary-3.6", 320 353 expected: pkg.Package{ 321 354 Name: "python", 322 - Version: "3.6.3a-vZ9", 323 - PURL: "pkg:generic/[email protected].3a-vZ9", 355 + Version: "3.6.3", 356 + PURL: "pkg:generic/[email protected].3", 324 357 Locations: locations("python3.6"), 325 358 Metadata: metadata("python-binary"), 326 359 }, 327 360 }, 328 361 { 329 - name: "positive-patchlevel.h", 330 - fixtureDir: "test-fixtures/classifiers/positive/python-source-3.9", 362 + name: "positive-python-duplicates", 363 + fixtureDir: "test-fixtures/classifiers/positive/python-duplicates", 331 364 expected: pkg.Package{ 332 365 Name: "python", 333 - Version: "3.9-aZ5", 334 - PURL: "pkg:generic/[email protected]", 335 - Locations: locations("patchlevel.h"), 336 - Metadata: metadata("cpython-source"), 366 + Version: "3.8.16", 367 + Type: "binary", 368 + PURL: "pkg:generic/[email protected]", 369 + Locations: locations("dir/python3.8", "python3.8", "libpython3.8.so"), 370 + Metadata: pkg.BinaryMetadata{ 371 + Matches: []pkg.ClassifierMatch{ 372 + match("python-binary", "dir/python3.8"), 373 + match("python-binary", "python3.8"), 374 + match("python-binary-lib", "libpython3.8.so"), 375 + }, 376 + }, 337 377 }, 338 378 }, 339 379 { skipped 151 lines 491 531 require.NoError(t, err) 492 532 493 533 for _, p := range packages { 494 - expectedLocations := test.expected.Locations.ToSlice() 495 - gotLocations := p.Locations.ToSlice() 496 - require.Len(t, gotLocations, len(expectedLocations)) 497 - 498 - for i, expectedLocation := range expectedLocations { 499 - gotLocation := gotLocations[i] 500 - if expectedLocation.RealPath != gotLocation.RealPath { 501 - t.Fatalf("locations do not match; expected: %v got: %v", expectedLocations, gotLocations) 502 - } 503 - } 504 - 505 534 assertPackagesAreEqual(t, test.expected, p) 506 535 } 507 536 }) skipped 103 lines 611 640 } 612 641 613 642 func assertPackagesAreEqual(t *testing.T, expected pkg.Package, p pkg.Package) { 643 + var failMessages []string 644 + expectedLocations := expected.Locations.ToSlice() 645 + gotLocations := p.Locations.ToSlice() 646 + 647 + if len(expectedLocations) != len(gotLocations) { 648 + failMessages = append(failMessages, "locations are not equal length") 649 + } else { 650 + for i, expectedLocation := range expectedLocations { 651 + gotLocation := gotLocations[i] 652 + if expectedLocation.RealPath != gotLocation.RealPath { 653 + failMessages = append(failMessages, fmt.Sprintf("locations do not match; expected: %v got: %v", expectedLocation.RealPath, gotLocation.RealPath)) 654 + } 655 + } 656 + } 657 + 614 658 m1 := expected.Metadata.(pkg.BinaryMetadata).Matches 615 659 m2 := p.Metadata.(pkg.BinaryMetadata).Matches 616 660 matches := true skipped 16 lines 633 677 } else { 634 678 matches = false 635 679 } 680 + 681 + if !matches { 682 + failMessages = append(failMessages, "classifier matches not equal") 683 + } 636 684 if expected.Name != p.Name || 637 685 expected.Version != p.Version || 638 - expected.PURL != p.PURL || 639 - !matches { 640 - assert.Failf(t, "packages not equal", "%v != %v", stringifyPkg(expected), stringifyPkg(p)) 686 + expected.PURL != p.PURL { 687 + failMessages = append(failMessages, "packages do not match") 641 688 } 642 - } 643 689 644 - func stringifyPkg(p pkg.Package) string { 645 - matches := p.Metadata.(pkg.BinaryMetadata).Matches 646 - return fmt.Sprintf("(name=%s, version=%s, purl=%s, matches=%+v)", p.Name, p.Version, p.PURL, matches) 690 + if len(failMessages) > 0 { 691 + assert.Failf(t, strings.Join(failMessages, "; "), "diff: %s", 692 + cmp.Diff(expected, p, 693 + cmp.Transformer("Locations", func(l source.LocationSet) []source.Location { 694 + return l.ToSlice() 695 + }), 696 + cmpopts.IgnoreUnexported(pkg.Package{}, source.Location{}), 697 + cmpopts.IgnoreFields(pkg.Package{}, "CPEs", "FoundBy", "MetadataType", "Type"), 698 + )) 699 + } 647 700 } 648 701 649 702 type panicyResolver struct { skipped 65 lines -
-
-
-
-
syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/python-binary-3.6/python3.6Binary file.
-
syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/python-duplicates/dir/python3.8Binary file.
-
syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/python-duplicates/libpython3.8.soBinary file.
-
syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/python-duplicates/python3.8Binary file.