Skip to content

Commit

Permalink
Test if in/out are terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jun 5, 2023
1 parent c5df450 commit 495c568
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 14 additions & 6 deletions pkg/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ func (o ExecClient) ExecuteCommand(ctx context.Context, command []string, podNam
return stdout, stderr, err
}

tty := term.TTY{
Raw: true,
In: os.Stdin,
Out: os.Stdout,
}
tty := setupTTY()

fn := func() error {
return o.platformClient.ExecCMDInContainer(ctx, containerName, podName, command, tty.Out, nil, tty.In, true)
return o.platformClient.ExecCMDInContainer(ctx, containerName, podName, command, tty.Out, os.Stderr, tty.In, tty.Raw)
}

return nil, nil, tty.Safe(fn)
Expand Down Expand Up @@ -116,3 +112,15 @@ func startReaderGoroutine(logWriter io.Writer, reader io.Reader, show bool, cmdO

return result
}

func setupTTY() term.TTY {
tty := term.TTY{
In: os.Stdin,
Out: os.Stdout,
}
if !tty.IsTerminalIn() || !tty.IsTerminalOut() {
return tty
}
tty.Raw = true
return tty
}
3 changes: 1 addition & 2 deletions tests/integration/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ var _ = Describe("odo run command tests", func() {
}

By("exiting with a status 1 when the exec command fails and displaying error output", func() {
// Err is in stdout and not stderr, as the terminal is set in raw mode
out := helper.Cmd("odo", "run", "error-cmd", "--platform", platform).ShouldFail().Out()
out := helper.Cmd("odo", "run", "error-cmd", "--platform", platform).ShouldFail().Err()
Expect(out).To(ContainSubstring("No such file or directory"))
})
})
Expand Down

0 comments on commit 495c568

Please sign in to comment.