Skip to content

Commit

Permalink
Reduce some of the noise in e2e tests by hiding the SBOM output unles…
Browse files Browse the repository at this point in the history
…s the test fails. (#453)

Signed-off-by: Dan Lorenc <dlorenc@google.com>
  • Loading branch information
dlorenc committed Jul 19, 2021
1 parent 9adaad5 commit 9ef97c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cmd/cosign/cli/download/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"flag"
"fmt"
"io"
"io/ioutil"
"os"

Expand All @@ -42,13 +43,13 @@ func SBOM() *ffcli.Command {
if len(args) != 1 {
return flag.ErrHelp
}
_, err := SBOMCmd(ctx, args[0])
_, err := SBOMCmd(ctx, args[0], os.Stdout)
return err
},
}
}

func SBOMCmd(ctx context.Context, imageRef string) ([]string, error) {
func SBOMCmd(ctx context.Context, imageRef string, out io.Writer) ([]string, error) {
ref, err := name.ParseReference(imageRef)
if err != nil {
return nil, err
Expand Down Expand Up @@ -87,7 +88,7 @@ func SBOMCmd(ctx context.Context, imageRef string) ([]string, error) {
return nil, err
}
sboms = append(sboms, string(sbom))
fmt.Println(string(sbom))
fmt.Fprintln(out, string(sbom))
}
return sboms, nil
}
8 changes: 6 additions & 2 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,22 @@ func TestAttachSBOM(t *testing.T) {
img, _, cleanup := mkimage(t, imgName)
defer cleanup()

_, err := download.SBOMCmd(ctx, img.Name())
out := bytes.Buffer{}
_, err := download.SBOMCmd(ctx, img.Name(), &out)
if err == nil {
t.Fatal("Expected error")
}
t.Log(out)
out.Reset()

// Upload it!
must(attach.SBOMCmd(ctx, "./testdata/bom-go-mod.spdx", "spdx", imgName), t)

sboms, err := download.SBOMCmd(ctx, imgName)
sboms, err := download.SBOMCmd(ctx, imgName, &out)
if err != nil {
t.Fatal(err)
}
t.Log(out)
if len(sboms) != 1 {
t.Fatalf("Expected one sbom, got %d", len(sboms))
}
Expand Down

0 comments on commit 9ef97c2

Please sign in to comment.