From 42d9a6b43bd9335fa30a52b2e0ed8912e14f6ac9 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 30 Jul 2020 20:45:14 -0700 Subject: [PATCH] tty.bats: add test cases when stdin is not a tty 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 --- tests/integration/tty.bats | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/integration/tty.bats b/tests/integration/tty.bats index 7193f327c..8d4919a27 100644 --- a/tests/integration/tty.bats +++ b/tests/integration/tty.bats @@ -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. # shellcheck disable=SC2016 @@ -61,6 +69,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