github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/test/integration/go_compiler_detection_test.go (about) 1 package integration 2 3 import ( 4 "testing" 5 6 "github.com/anchore/syft/syft/cpe" 7 "github.com/anchore/syft/syft/source" 8 ) 9 10 func TestGolangCompilerDetection(t *testing.T) { 11 tests := []struct { 12 name string 13 image string 14 expectedCompilers []string 15 expectedCPE []cpe.CPE 16 expectedPURL []string 17 }{ 18 { 19 name: "syft can detect a single golang compiler given the golang base image", 20 image: "image-golang-compiler", 21 expectedCompilers: []string{"go1.18.10"}, 22 expectedCPE: []cpe.CPE{cpe.Must("cpe:2.3:a:golang:go:1.18.10:-:*:*:*:*:*:*")}, 23 expectedPURL: []string{"pkg:golang/stdlib@1.18.10"}, 24 }, 25 } 26 for _, tt := range tests { 27 t.Run(tt.name, func(t *testing.T) { 28 sbom, _ := catalogFixtureImage(t, tt.image, source.SquashedScope, nil) 29 packages := sbom.Artifacts.Packages.PackagesByName("stdlib") 30 31 foundCompilerVersions := make(map[string]struct{}) 32 foundCPE := make(map[cpe.CPE]struct{}) 33 foundPURL := make(map[string]struct{}) 34 35 for _, pkg := range packages { 36 foundCompilerVersions[pkg.Version] = struct{}{} 37 foundPURL[pkg.PURL] = struct{}{} 38 for _, cpe := range pkg.CPEs { 39 foundCPE[cpe] = struct{}{} 40 } 41 } 42 43 for _, expectedCompiler := range tt.expectedCompilers { 44 if _, ok := foundCompilerVersions[expectedCompiler]; !ok { 45 t.Fatalf("expected %s version; not found in found compilers: %v", expectedCompiler, foundCompilerVersions) 46 } 47 } 48 49 for _, expectedPURL := range tt.expectedPURL { 50 if _, ok := foundPURL[expectedPURL]; !ok { 51 t.Fatalf("expected %s purl; not found in found purl: %v", expectedPURL, expectedPURLs) 52 } 53 } 54 55 for _, expectedCPE := range tt.expectedCPE { 56 if _, ok := foundCPE[expectedCPE]; !ok { 57 t.Fatalf("expected %s version; not found in found cpe: %v", expectedCPE, expectedCPE) 58 } 59 } 60 }) 61 } 62 }