Skip to content

Commit 4cef47c

Browse files
committed
[2930] Added test for SBOM feature
Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com>
1 parent 60c6053 commit 4cef47c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pkg/porter/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func (p *Porter) generateSBOM(ctx context.Context, bundleRef cnab.BundleReferenc
413413
}
414414

415415
log.Infof("SBOM for bundle %s written to %s", bundleRef.Reference.String(), sbomPath)
416-
return nil
416+
return err
417417
}
418418

419419
// extractBundle extracts a bundle using the provided opts and returns the extracted bundle

pkg/porter/publish_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package porter
33
import (
44
"context"
55
"errors"
6+
"fmt"
7+
"os"
68
"runtime"
9+
"strings"
710
"testing"
811
"time"
912

@@ -329,3 +332,31 @@ func TestPublish_ForceOverwrite(t *testing.T) {
329332
})
330333
}
331334
}
335+
336+
func TestPublish_SBOM(t *testing.T) {
337+
p := NewTestPorter(t)
338+
defer p.Close()
339+
340+
p.TestConfig.TestContext.AddTestFile("testdata/porter.yaml", "porter.yaml")
341+
342+
f, err := os.CreateTemp(t.TempDir(), "sbom.json")
343+
if err != nil {
344+
t.Fatal(err)
345+
}
346+
opts := PublishOptions{SBOMPath: f.Name()}
347+
348+
err = opts.Validate(p.Config)
349+
require.NoError(t, err)
350+
351+
ctx := context.Background()
352+
err = p.Publish(ctx, opts)
353+
354+
require.NoError(t, err)
355+
356+
b, err := os.ReadFile(f.Name())
357+
if err != nil {
358+
t.Fatal(err)
359+
}
360+
s := string(b)
361+
fmt.Println(strings.Contains(s, "SPDX-2.3"))
362+
}

0 commit comments

Comments
 (0)