Skip to content

combined output for integration tests skaffold runner #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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