From ebba957fad12e2672f3e18e79644101d3205df4b Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Mon, 20 Jan 2025 16:18:25 +0100 Subject: [PATCH] test: add combi test sbom/manifest Signed-off-by: Simon de Vlieger --- cmd/image-builder/main_test.go | 45 ++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index d9112d2..8f85a21 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -394,7 +394,7 @@ func TestBuildIntegrationSwitchOutputDir(t *testing.T) { assert.Equal(t, "some-output-dir", osbuildCall[outputDirPos+1]) } -func TestBuildIntegrationExtraArtifactsManifest(t *testing.T) { +func TestBuildIntegrationWithManifest(t *testing.T) { if testing.Short() { t.Skip("manifest generation takes a while") } @@ -470,7 +470,7 @@ exit 1 assert.Equal(t, "error on stderr\n", fakeStderr.String()) } -func TestManifestIntegrationExtraArtifactsSBOMWithOutputDir(t *testing.T) { +func TestManifestIntegrationWithSBOMWithOutputDir(t *testing.T) { if testing.Short() { t.Skip("manifest generation takes a while") } @@ -506,3 +506,44 @@ func TestManifestIntegrationExtraArtifactsSBOMWithOutputDir(t *testing.T) { assert.Equal(t, filepath.Join(outputDir, "centos-9-qcow2-x86_64.buildroot-build.spdx.json"), sboms[0]) assert.Equal(t, filepath.Join(outputDir, "centos-9-qcow2-x86_64.image-os.spdx.json"), sboms[1]) } + +func TestBuildIntegrationWithManifestWithSBOM(t *testing.T) { + if testing.Short() { + t.Skip("manifest generation takes a while") + } + if !hasDepsolveDnf() { + t.Skip("no osbuild-depsolve-dnf binary found") + } + + restore := main.MockNewRepoRegistry(testrepos.New) + defer restore() + + outputDir := t.TempDir() + restore = main.MockOsArgs([]string{ + "build", + "qcow2", + "--distro", "centos-9", + "--cache", outputDir, + "--with-manifest", + "--with-sbom", + "--output-dir", outputDir, + }) + defer restore() + + script := `cat - > "$0".stdin` + fakeOsbuildCmd := testutil.MockCommand(t, "osbuild", script) + defer fakeOsbuildCmd.Restore() + + err := main.Run() + assert.NoError(t, err) + + manifest, err := filepath.Glob(filepath.Join(outputDir, "*.osbuild-manifest.json")) + assert.Equal(t, len(manifest), 1) + assert.Equal(t, filepath.Join(outputDir, "centos-9-qcow2-x86_64.osbuild-manifest.json"), manifest[0]) + + sboms, err := filepath.Glob(filepath.Join(outputDir, "*.spdx.json")) + assert.NoError(t, err) + assert.Equal(t, len(sboms), 2) + assert.Equal(t, filepath.Join(outputDir, "centos-9-qcow2-x86_64.buildroot-build.spdx.json"), sboms[0]) + assert.Equal(t, filepath.Join(outputDir, "centos-9-qcow2-x86_64.image-os.spdx.json"), sboms[1]) +}