github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/cmd/syft/internal/test/integration/regression_sbom_duplicate_relationships_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/scylladb/go-set/strset" 8 9 "github.com/anchore/syft/syft/source" 10 ) 11 12 func TestRelationshipsUnique(t *testing.T) { 13 // This test is to ensure that the relationships are deduplicated in the final SBOM. 14 // It is not a test of the relationships themselves. 15 // This test is a regression test for #syft/2509 16 sbom, _ := catalogFixtureImage(t, "image-pkg-coverage", source.SquashedScope) 17 observedRelationships := strset.New() 18 19 for _, rel := range sbom.Relationships { 20 unique := fmt.Sprintf("%s:%s:%s", rel.From.ID(), rel.To.ID(), rel.Type) 21 if observedRelationships.Has(unique) { 22 t.Errorf("duplicate relationship found: %s", unique) 23 } 24 observedRelationships.Add(unique) 25 } 26 }