test: add combi test sbom/manifest

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2025-01-20 16:18:25 +01:00
parent 613f56e7d2
commit ebba957fad

View file

@ -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])
}