Skip to content

Commit

Permalink
output stdout, stderr when command fails
Browse files Browse the repository at this point in the history
Authored-by: Larry Hamel <lhamel@pivotal.io>
  • Loading branch information
Larry Hamel committed Jun 5, 2020
1 parent cd63fd2 commit 5a33b15
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/gbytes"
)

func readAll(buffer *gbytes.Buffer) string {
bytes, err := ioutil.ReadAll(buffer)
if err != nil {
return "cannot read buffer: " + err.Error()
}
return string(bytes)
}


func RunSuccessfully(description, cmd string, args ...string) *gexec.Session {
session := runCommand(description, GinkgoWriter, cmd, args...)
Expect(session).To(gexec.Exit(0), "Command errored: "+description)
buffer := gbytes.NewBuffer()
session := runCommand(description, buffer, cmd, args...)
Expect(session).To(gexec.Exit(0), "Command errored: "+description + "\n" + readAll(buffer))
return session
}

Expand Down

0 comments on commit 5a33b15

Please sign in to comment.