Skip to content

Commit

Permalink
tty.bats: add test cases when stdin is not a tty
Browse files Browse the repository at this point in the history
Note that stdout/stderr are already redirected by bats'
`run` command, so the only way to get a controlling terminal
is to open /dev/tty (which fails if there isn't one).

Here's how I tested the failure to open /dev/tty:

> [root@kir-rhat ~]# ssh -T root@localhost cat ./runme
> cd /home/kir/go/src/github.com/opencontainers/runc
> ./runc run -b tst xxx-$$
> echo $?
>
> [root@kir-rhat ~]# ssh -T root@localhost ./runme
> time="2020-07-31T16:35:47-07:00" level=error msg="chdir tst: no such file or directory"
> 1

If anyone knows how to obtain an tty-less environment without using
ssh -T, please raise your hand.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 31, 2020
1 parent ea7b1ff commit d1a3550
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/integration/tty.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ function teardown() {
teardown_busybox
}

@test "runc run [stdin not a tty]" {
# stty size fails without a tty
update_config '(.. | select(.[]? == "sh")) += ["-c", "stty size"]'
# note that stdout/stderr are already redirected by bats' run
runc run test_busybox < /dev/null
[ "$status" -eq 0 ]
}

@test "runc run [tty ptsname]" {
# Replace sh script with readlink.
update_config '(.. | select(.[]? == "sh")) += ["-c", "for file in /proc/self/fd/[012]; do readlink $file; done"]'
Expand Down Expand Up @@ -58,6 +66,18 @@ function teardown() {
[[ ${lines[1]} =~ 5 ]]
}

@test "runc exec [stdin not a tty]" {
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
[ "$status" -eq 0 ]

# make sure we're running
testcontainer test_busybox running

# note that stdout/stderr are already redirected by bats' run
runc exec -t test_busybox sh -c "stty size" < /dev/null
[ "$status" -eq 0 ]
}

@test "runc exec [tty ptsname]" {
# run busybox detached
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
Expand Down

0 comments on commit d1a3550

Please sign in to comment.