github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/format/internal/testutil/file_relationships.go (about) 1 package testutil 2 3 import ( 4 "math/rand" 5 "time" 6 7 "github.com/anchore/syft/syft/artifact" 8 "github.com/anchore/syft/syft/file" 9 "github.com/anchore/syft/syft/sbom" 10 ) 11 12 //nolint:gosec 13 func AddSampleFileRelationships(s *sbom.SBOM) { 14 catalog := s.Artifacts.Packages.Sorted() 15 s.Artifacts.FileMetadata = map[file.Coordinates]file.Metadata{} 16 17 files := []string{"/f1", "/f2", "/d1/f3", "/d2/f4", "/z1/f5", "/a1/f6"} 18 rnd := rand.New(rand.NewSource(time.Now().UnixNano())) 19 rnd.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] }) 20 21 for _, f := range files { 22 meta := file.Metadata{} 23 coords := file.Coordinates{RealPath: f} 24 s.Artifacts.FileMetadata[coords] = meta 25 26 s.Relationships = append(s.Relationships, artifact.Relationship{ 27 From: catalog[0], 28 To: coords, 29 Type: artifact.ContainsRelationship, 30 }) 31 } 32 }