Skip to content

Commit

Permalink
Merge pull request #1800 from balopat/stderr_for_integration_tests
Browse files Browse the repository at this point in the history
combined output for integration tests skaffold runner
  • Loading branch information
dgageot committed Mar 15, 2019
2 parents 5fa4ce3 + d182f45 commit 891f9b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration/fix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestFix(t *testing.T) {
ns, _, deleteNs := SetupNamespace(t)
defer deleteNs()

out := skaffold.Fix().WithConfig("skaffold.yaml").InDir("testdata/fix").RunOrFail(t)
out := skaffold.Fix().WithConfig("skaffold.yaml").InDir("testdata/fix").RunOrFailStdOutOnly(t)

skaffold.Run().WithConfig("-").InDir("testdata/fix").InNs(ns.Name).WithStdin(out).RunOrFail(t)
}
29 changes: 27 additions & 2 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,27 @@ func (b *RunBuilder) RunBackground(t *testing.T) context.CancelFunc {
}
}

// Run runs the skaffold command and returns its output.
// Run runs the skaffold command and returns its std output and std err combined.
func (b *RunBuilder) Run(t *testing.T) ([]byte, error) {
t.Helper()

cmd := b.cmd(context.Background())
logrus.Infoln(cmd.Args)

start := time.Now()
out, err := cmd.CombinedOutput()
logrus.Infoln("Ran in", time.Since(start))

return out, err
}

// Run runs the skaffold command and returns its std output.
func (b *RunBuilder) RunStdOutOnly(t *testing.T) ([]byte, error) {
t.Helper()

cmd := b.cmd(context.Background())
logrus.Infoln(cmd.Args)

start := time.Now()
out, err := cmd.Output()
logrus.Infoln("Ran in", time.Since(start))
Expand All @@ -163,7 +177,7 @@ func (b *RunBuilder) Run(t *testing.T) ([]byte, error) {
}

// RunOrFail runs the skaffold command and fails the test
// if the command returns an error.
// if the command returns an error. It returns the combined standard output and standard error.
func (b *RunBuilder) RunOrFail(t *testing.T) []byte {
t.Helper()
out, err := b.Run(t)
Expand All @@ -173,6 +187,17 @@ func (b *RunBuilder) RunOrFail(t *testing.T) []byte {
return out
}

// RunOrFailStdOutOnly runs the skaffold command and fails the test
// if the command returns an error. It only returns the standard output.
func (b *RunBuilder) RunOrFailStdOutOnly(t *testing.T) []byte {
t.Helper()
out, err := b.RunStdOutOnly(t)
if err != nil {
t.Fatalf("skaffold %s: %v, %s", b.command, err, out)
}
return out
}

func (b *RunBuilder) cmd(ctx context.Context) *exec.Cmd {
args := []string{b.command}
if b.ns != "" {
Expand Down

0 comments on commit 891f9b0

Please sign in to comment.