mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
524803ccd6
The idea of commitd1fca8ewas right (report errors for non-existent root, unless using the default root dir) but the logic was inverted. Fix the logic. Test case for default root requires non-existent /root/runc, which is not always possible. [v1.5 backport: use GlobalIsSet] Reported-by: RedMakeUp <girafeeblue@gmail.com> Co-authored-by: RedMakeUp <girafeeblue@gmail.com> Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> (cherry picked from commit98c442a0e6) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
66 lines
2.4 KiB
Bash
66 lines
2.4 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load helpers
|
|
|
|
function setup() {
|
|
setup_busybox
|
|
ALT_ROOT="$ROOT/alt"
|
|
mkdir -p "$ALT_ROOT/state"
|
|
}
|
|
|
|
function teardown() {
|
|
ROOT="$ALT_ROOT" teardown_bundle
|
|
unset ALT_ROOT
|
|
teardown_bundle
|
|
}
|
|
|
|
@test "list" {
|
|
bundle=$(pwd)
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box1
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box2
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc run -d --console-socket "$CONSOLE_SOCKET" test_box3
|
|
[ "$status" -eq 0 ]
|
|
|
|
ROOT=$ALT_ROOT runc list
|
|
[ "$status" -eq 0 ]
|
|
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
|
|
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
|
|
ROOT=$ALT_ROOT runc list -q
|
|
[ "$status" -eq 0 ]
|
|
[ "${lines[0]}" = "test_box1" ]
|
|
[ "${lines[1]}" = "test_box2" ]
|
|
[ "${lines[2]}" = "test_box3" ]
|
|
|
|
ROOT=$ALT_ROOT runc list --format table
|
|
[ "$status" -eq 0 ]
|
|
[[ ${lines[0]} =~ ID\ +PID\ +STATUS\ +BUNDLE\ +CREATED+ ]]
|
|
[[ "${lines[1]}" == *"test_box1"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[2]}" == *"test_box2"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
[[ "${lines[3]}" == *"test_box3"*[0-9]*"running"*$bundle*[0-9]* ]]
|
|
|
|
ROOT=$ALT_ROOT runc list --format json
|
|
[ "$status" -eq 0 ]
|
|
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
|
|
}
|
|
|
|
@test "list with non-existent root fails" {
|
|
ROOT=/non-existent-dir runc list
|
|
[ "$status" -ne 0 ]
|
|
}
|
|
|
|
@test "list with default non-existent root succeeds" {
|
|
requires root # rootless auto-creates a directory under $XDG_RUNTIME_DIR.
|
|
test -d /root/runc && skip "requires missing /root/runc"
|
|
ROOT='' runc list
|
|
[ "$status" -eq 0 ]
|
|
}
|