From 9ef97c2ba8b9c4dab5be344d8f950254f30989b4 Mon Sep 17 00:00:00 2001 From: dlorenc Date: Mon, 19 Jul 2021 08:38:27 -0500 Subject: [PATCH] Reduce some of the noise in e2e tests by hiding the SBOM output unless the test fails. (#453) Signed-off-by: Dan Lorenc --- cmd/cosign/cli/download/sbom.go | 7 ++++--- test/e2e_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/cosign/cli/download/sbom.go b/cmd/cosign/cli/download/sbom.go index 8c1df9c147f..feb35a1dbe8 100644 --- a/cmd/cosign/cli/download/sbom.go +++ b/cmd/cosign/cli/download/sbom.go @@ -19,6 +19,7 @@ import ( "context" "flag" "fmt" + "io" "io/ioutil" "os" @@ -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 @@ -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 } diff --git a/test/e2e_test.go b/test/e2e_test.go index a81c5303f43..84b6fcaea8c 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -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)) }