From 55dc5896af71650dfdb7e503db206a819a29cc75 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Sun, 22 Jan 2023 13:37:01 -0600 Subject: [PATCH 1/2] fix compare tool generation and add better testing --- src/internal/packager/sbom/catalog.go | 2 +- src/test/e2e/06_create_sbom_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/internal/packager/sbom/catalog.go b/src/internal/packager/sbom/catalog.go index f6b3dc7678..d3f5b589cd 100644 --- a/src/internal/packager/sbom/catalog.go +++ b/src/internal/packager/sbom/catalog.go @@ -106,7 +106,7 @@ func Catalog(componentSBOMs map[string]*types.ComponentSBOM, tagToImage map[name currImage++ } - if len(componentSBOMs) > 0 && len(tagToImage) > 0 { + if len(componentSBOMs) > 0 || len(tagToImage) > 0 { if err := builder.createSBOMCompareAsset(); err != nil { builder.spinner.Fatalf(err, "Unable to create SBOM compare tool") } diff --git a/src/test/e2e/06_create_sbom_test.go b/src/test/e2e/06_create_sbom_test.go index 5e57259ee5..c8a81508ad 100644 --- a/src/test/e2e/06_create_sbom_test.go +++ b/src/test/e2e/06_create_sbom_test.go @@ -28,6 +28,8 @@ func TestCreateSBOM(t *testing.T) { // Test that the game package generates the SBOMs we expect (images only) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) require.NoError(t, err) + _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "compare.html")) + require.NoError(t, err) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "defenseunicorns_zarf-game_multi-tile-dark.json")) require.NoError(t, err) @@ -39,6 +41,8 @@ func TestCreateSBOM(t *testing.T) { // Test that the game package generates the SBOMs we expect (images only) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-defenseunicorns_zarf-game_multi-tile-dark.html")) require.NoError(t, err) + _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "compare.html")) + require.NoError(t, err) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "defenseunicorns_zarf-game_multi-tile-dark.json")) require.NoError(t, err) @@ -62,6 +66,8 @@ func TestCreateSBOM(t *testing.T) { require.NoError(t, err) _, err = os.ReadFile(filepath.Join(sbomPath, "init", "zarf-component-k3s.json")) require.NoError(t, err) + _, err = os.ReadFile(filepath.Join(sbomPath, "init", "compare.html")) + require.NoError(t, err) e2e.cleanFiles(cachePath, sbomPath, pkgName) } From 13bd286a63f0ac0eddd432fd690e2b3c103a7177 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Sun, 22 Jan 2023 16:19:39 -0600 Subject: [PATCH 2/2] Add a comment per feedback --- src/internal/packager/sbom/catalog.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/internal/packager/sbom/catalog.go b/src/internal/packager/sbom/catalog.go index d3f5b589cd..244b1a4df6 100644 --- a/src/internal/packager/sbom/catalog.go +++ b/src/internal/packager/sbom/catalog.go @@ -106,6 +106,7 @@ func Catalog(componentSBOMs map[string]*types.ComponentSBOM, tagToImage map[name currImage++ } + // Include the compare tool if there are any image SBOMs OR component SBOMs if len(componentSBOMs) > 0 || len(tagToImage) > 0 { if err := builder.createSBOMCompareAsset(); err != nil { builder.spinner.Fatalf(err, "Unable to create SBOM compare tool")