github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/test/integration/package_ownership_relationship_test.go (about) 1 package integration 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "testing" 7 8 "github.com/nextlinux/gosbom/gosbom/formats/gosbomjson" 9 gosbomjsonModel "github.com/nextlinux/gosbom/gosbom/formats/gosbomjson/model" 10 "github.com/nextlinux/gosbom/gosbom/source" 11 ) 12 13 func TestPackageOwnershipRelationships(t *testing.T) { 14 15 // ensure that the json encoder is applying artifact ownership with an image that has expected ownership relationships 16 tests := []struct { 17 fixture string 18 }{ 19 { 20 fixture: "image-owning-package", 21 }, 22 } 23 24 for _, test := range tests { 25 t.Run(test.fixture, func(t *testing.T) { 26 sbom, _ := catalogFixtureImage(t, test.fixture, source.SquashedScope, nil) 27 28 output := bytes.NewBufferString("") 29 err := gosbomjson.Format().Encode(output, sbom) 30 if err != nil { 31 t.Fatalf("unable to present: %+v", err) 32 } 33 34 var doc gosbomjsonModel.Document 35 decoder := json.NewDecoder(output) 36 if err := decoder.Decode(&doc); err != nil { 37 t.Fatalf("unable to decode json doc: %+v", err) 38 } 39 40 if len(doc.ArtifactRelationships) == 0 { 41 t.Errorf("expected to find relationships between packages but found none") 42 } 43 44 }) 45 } 46 47 }