Files
Kir Kolyshkin 07cd18c9c9 tests/int: use assert for substring and regexp comparisons
The point of the assert helpers is that a failed test says what it
wanted and what it got, so leaving most comparisons as bare [[ ]]
defeats it.

Convert the rest of the checks on $output and $lines. Those using a glob
to look for a substring become --partial, the rest become --regexp (the
patterns are translated to extended regular expressions, and anchored
where the glob was).

The few remaining [[ ]] are not assertions: one is an if condition, and
another one is the left hand side of ||, offering an alternative to the
assert that follows it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-10-02 14:47:43 -07:00

66 lines
1.5 KiB
Bash

#!/usr/bin/env bats
load helpers
function setup() {
setup_busybox
update_config '.process.args = ["/bin/echo", "Hello World"]'
}
function teardown() {
teardown_bundle
}
function check_debug() {
[[ "$*" == *"nsexec container setup"* ]]
[[ "$*" == *"child process in init()"* ]]
[[ "$*" == *"init: closing the pipe to signal completion"* ]]
}
@test "global --debug" {
run -0 runc --debug run test_hello
# check expected debug output was sent to stderr
assert_output --partial "level=debug"
check_debug "$output"
}
@test "global --debug to --log" {
run -0 runc --log log.out --debug run test_hello
# check output does not include debug info
refute_output --partial "level=debug"
cat log.out >&2
# check expected debug output was sent to log.out
output=$(cat log.out)
assert_output --partial "level=debug"
check_debug "$output"
}
@test "global --debug to --log --log-format 'text'" {
run -0 runc --log log.out --log-format "text" --debug run test_hello
# check output does not include debug info
refute_output --partial "level=debug"
cat log.out >&2
# check expected debug output was sent to log.out
output=$(cat log.out)
assert_output --partial "level=debug"
check_debug "$output"
}
@test "global --debug to --log --log-format 'json'" {
run -0 runc --log log.out --log-format "json" --debug run test_hello
# check output does not include debug info
refute_output --partial "level=debug"
cat log.out >&2
# check expected debug output was sent to log.out
output=$(cat log.out)
assert_output --partial '"level":"debug"'
check_debug "$output"
}