diff --git a/integration/fix_test.go b/integration/fix_test.go index e6570c8e22d..bc8a2fa740a 100644 --- a/integration/fix_test.go +++ b/integration/fix_test.go @@ -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) } diff --git a/integration/skaffold/helper.go b/integration/skaffold/helper.go index e55c77b6ab4..dac89c5747f 100644 --- a/integration/skaffold/helper.go +++ b/integration/skaffold/helper.go @@ -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)) @@ -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) @@ -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 != "" {