github.com/anchore/syft@v1.38.2/internal/os/feature_detection_test.go (about) 1 package os_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 "github.com/anchore/stereoscope/pkg/imagetest" 10 "github.com/anchore/syft/internal/os" 11 "github.com/anchore/syft/internal/sbomsync" 12 "github.com/anchore/syft/internal/task" 13 "github.com/anchore/syft/syft" 14 "github.com/anchore/syft/syft/linux" 15 "github.com/anchore/syft/syft/sbom" 16 "github.com/anchore/syft/syft/source" 17 ) 18 19 func Test_EnvironmentTask(t *testing.T) { 20 tests := []struct { 21 name string 22 expected linux.Release 23 }{ 24 { 25 name: "not_rhel", 26 expected: linux.Release{ 27 PrettyName: "Red Hat Enterprise Linux 9.4 (Plow)", 28 Name: "Red Hat Enterprise Linux", 29 ID: "not-rhel", 30 IDLike: []string{ 31 "fedora", 32 }, 33 Version: "9.4 (Plow)", 34 VersionID: "9.4", 35 HomeURL: "https://www.redhat.com/", 36 BugReportURL: "https://issues.redhat.com/", 37 CPEName: "cpe:/o:redhat:enterprise_linux:9::baseos", 38 ExtendedSupport: false, // important 39 }, 40 }, 41 { 42 name: "rhel_content_manifests", 43 expected: linux.Release{ 44 PrettyName: "Red Hat Enterprise Linux 9.4 (Plow)", 45 Name: "Red Hat Enterprise Linux", 46 ID: "rhel", 47 IDLike: []string{ 48 "fedora", 49 }, 50 Version: "9.4 (Plow)", 51 VersionID: "9.4", 52 HomeURL: "https://www.redhat.com/", 53 BugReportURL: "https://issues.redhat.com/", 54 CPEName: "cpe:/o:redhat:enterprise_linux:9::baseos", 55 ExtendedSupport: true, // important 56 }, 57 }, 58 { 59 name: "rhel_no_manifests", 60 expected: linux.Release{ 61 PrettyName: "Red Hat Enterprise Linux 9.4 (Plow)", 62 Name: "Red Hat Enterprise Linux", 63 ID: "rhel", 64 IDLike: []string{ 65 "fedora", 66 }, 67 Version: "9.4 (Plow)", 68 VersionID: "9.4", 69 HomeURL: "https://www.redhat.com/", 70 BugReportURL: "https://issues.redhat.com/", 71 CPEName: "cpe:/o:redhat:enterprise_linux:9::baseos", 72 ExtendedSupport: false, // important 73 }, 74 }, 75 } 76 77 for _, test := range tests { 78 t.Run(test.name, func(t *testing.T) { 79 tarPath := imagetest.GetFixtureImageTarPath(t, test.name) 80 81 // get the source 82 theSource, err := syft.GetSource(context.Background(), tarPath, syft.DefaultGetSourceConfig().WithSources("docker-archive")) 83 require.NoError(t, err) 84 t.Cleanup(func() { 85 require.NoError(t, theSource.Close()) 86 }) 87 88 resolver, err := theSource.FileResolver(source.SquashedScope) 89 require.NoError(t, err) 90 91 s := sbom.SBOM{} 92 err = task.NewEnvironmentTask().Execute(context.Background(), resolver, sbomsync.NewBuilder(&s)) 93 require.NoError(t, err) 94 95 err = os.DetectFeatures(context.Background(), resolver, sbomsync.NewBuilder(&s)) 96 require.NoError(t, err) 97 98 require.Equal(t, &test.expected, s.Artifacts.LinuxDistribution) 99 }) 100 } 101 }