toolbox/test/system/104-run.bats
Ondřej Míchal 16b0c5d88f test/system: Check whole lines instead of partials
The 'toolbox run' command has one downside: all newlines contain
a carriage return (CR). This is caused by the unconditional use of the
--tty option in `podman exec`[0]. In these particular tests this can be
worked around by not printing a newline at all.

Another quirk around partial is to check the last line of the output.

[0] https://github.com/containers/podman/issues/9718

https://github.com/containers/toolbox/pull/843
2021-07-21 23:43:41 +02:00

59 lines
1.4 KiB
Bash

#!/usr/bin/env bats
load 'libs/bats-support/load'
load 'libs/bats-assert/load'
load 'libs/helpers'
# It seems like 'toolbox run' (or 'enter') doesn't work fine when
# the workdir is outside the $HOME.
# This hack is to make the tests work from outside the $HOME.
readonly CURDIR=$PWD
setup() {
cd "$HOME" || return 1
cleanup_containers
}
teardown() {
cleanup_containers
cd "$CURDIR" || return 1
}
@test "run: Try to run echo 'Hello World' with no containers created" {
run $TOOLBOX run echo "Hello World"
assert_failure
assert_line --index 0 --regexp 'Error: container .* not found'
assert_output --partial "Run 'toolbox --help' for usage."
}
@test "run: Run echo 'Hello World' inside of the default container" {
create_default_container
run $TOOLBOX --verbose run echo -n "Hello World"
assert_success
assert_line --index $((${#lines[@]}-1)) "Hello World"
}
@test "run: Run echo 'Hello World' inside a container after being stopped" {
create_container running
start_container running
stop_container running
run $TOOLBOX --verbose run --container running echo -n "Hello World"
assert_success
assert_line --index $((${#lines[@]}-1)) "Hello World"
}
@test "run: Run sudo id inside of the default container" {
create_default_container
run $TOOLBOX --verbose run sudo id
assert_success
assert_line --index $((${#lines[@]}-1)) --partial "uid=0(root)"
}