spiegel_podman/test/system/450-interactive.bats
Ed Santiago c2575f726d sys tests: run_podman: check for unwanted warnings/errors
With few exceptions, commands that exit 0 should not emit any
messages with level=warning or =error. Let's start enforcing
that in run_podman.

Allow one-off exceptions, typically when we're testing an
actual warning condition (usual case: "podman stop" where it
times out to SIGKILL). Exceptions are specified via:

    run_podman 0+w subcommand...
               ^^^---- or, rarely, 0+e

"0" stands for "expect exit status 0", which is the default
so it's implicit anyway. The +w / +e (or even +we) is the
new part. I have added it to tests where necessary.

And, because life is what it is, add two global exceptions:

  - Debian. Because runc has too many flakes.
  - kube. Ditto. Kube commands emit lots of nasty error
    messages (yes, level=error) that don't seem to affect
    results.

Similar to #18442

Signed-off-by: Ed Santiago <santiago@redhat.com>
2023-09-07 05:35:21 -06:00

98 lines
2.9 KiB
Bash

# -*- bats -*-
#
# tests of podman commands that require an interactive pty
#
load helpers
###############################################################################
# BEGIN setup/teardown
# Each test runs with its own PTY, managed by socat.
PODMAN_TEST_PTY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_pty.XXXXXX)
PODMAN_DUMMY=$(mktemp -u --tmpdir=${BATS_TMPDIR:-/tmp} podman_dummy.XXXXXX)
PODMAN_SOCAT_PID=
function setup() {
basic_setup
# Create a pty. Run under 'timeout' because BATS reaps child processes
# and if we exit before killing socat, bats will hang forever.
timeout 10 socat \
PTY,link=$PODMAN_TEST_PTY,raw,echo=0 \
PTY,link=$PODMAN_DUMMY,raw,echo=0 &
PODMAN_SOCAT_PID=$!
# Wait for pty
retries=5
while [[ ! -e $PODMAN_TEST_PTY ]]; do
retries=$(( retries - 1 ))
assert $retries -gt 0 "Timed out waiting for $PODMAN_TEST_PTY"
sleep 0.5
done
}
function teardown() {
if [[ -n $PODMAN_SOCAT_PID ]]; then
kill $PODMAN_SOCAT_PID
PODMAN_SOCAT_PID=
fi
rm -f $PODMAN_TEST_PTY $PODMAN_DUMMY_PTY
basic_teardown
}
# END setup/teardown
###############################################################################
# BEGIN tests
@test "podman detects correct tty size" {
# Set the pty to a random size. Make rows/columns odd/even, to guarantee
# that they can never be the same
rows=$(( 15 + RANDOM % 60 | 1 ))
cols=$(( 15 + RANDOM % 60 & 126 ))
stty rows $rows cols $cols <$PODMAN_TEST_PTY
CR=$'\r'
# ...and make sure stty under podman reads that.
run_podman run -it --name mystty $IMAGE stty size <$PODMAN_TEST_PTY
is "$output" "$rows $cols$CR" "stty under podman run reads the correct dimensions"
run_podman rm -t 0 -f mystty
# FIXME: the checks below are flaking a lot (see #10710).
# check that the same works for podman exec
# run_podman run -d --name mystty $IMAGE top
# run_podman exec -it mystty stty size <$PODMAN_TEST_PTY
# is "$output" "$rows $cols" "stty under podman exec reads the correct dimensions"
#
# run_podman rm -t 0 -f mystty
}
@test "podman load - will not read from tty" {
run_podman 125 load <$PODMAN_TEST_PTY
is "$output" \
"Error: cannot read from terminal, use command-line redirection or the --input flag" \
"Diagnostic from 'podman load' without redirection or -i"
}
@test "podman run --tty -i failure with no tty" {
run_podman 0+w run --tty -i --rm $IMAGE echo hello < /dev/null
is "$output" ".*The input device is not a TTY.*" "-it _without_ a tty"
CR=$'\r'
run_podman run --tty -i --rm $IMAGE echo hello <$PODMAN_TEST_PTY
is "$output" "hello$CR" "-it _with_ a pty"
run_podman run --tty=false -i --rm $IMAGE echo hello < /dev/null
is "$output" "hello" "-tty=false: no warning"
run_podman run --tty -i=false --rm $IMAGE echo hello < /dev/null
is "$output" "hello$CR" "-i=false: no warning"
}
# vim: filetype=sh