...
1#!/usr/bin/env bats
2
3load helpers
4
5function setup() {
6 setup_busybox
7}
8
9function teardown() {
10 teardown_bundle
11}
12
13@test "runc run detached" {
14 # run busybox detached
15 runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
16 [ "$status" -eq 0 ]
17
18 # check state
19 testcontainer test_busybox running
20}
21
22@test "runc run detached ({u,g}id != 0)" {
23 # cannot start containers as another user in rootless setup without idmap
24 [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
25
26 # replace "uid": 0 with "uid": 1000
27 # and do a similar thing for gid.
28 update_config ' (.. | select(.uid? == 0)) .uid |= 1000
29 | (.. | select(.gid? == 0)) .gid |= 100'
30
31 # run busybox detached
32 runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox
33 [ "$status" -eq 0 ]
34
35 # check state
36 testcontainer test_busybox running
37}
38
39@test "runc run detached --pid-file" {
40 # run busybox detached
41 runc run --pid-file pid.txt -d --console-socket "$CONSOLE_SOCKET" test_busybox
42 [ "$status" -eq 0 ]
43
44 # check state
45 testcontainer test_busybox running
46
47 # check pid.txt was generated
48 [ -e pid.txt ]
49
50 [[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
51}
52
53@test "runc run detached --pid-file with new CWD" {
54 bundle="$(pwd)"
55 # create pid_file directory as the CWD
56 mkdir pid_file
57 cd pid_file
58
59 # run busybox detached
60 runc run --pid-file pid.txt -d -b "$bundle" --console-socket "$CONSOLE_SOCKET" test_busybox
61 [ "$status" -eq 0 ]
62
63 # check state
64 testcontainer test_busybox running
65
66 # check pid.txt was generated
67 [ -e pid.txt ]
68
69 [[ "$(cat pid.txt)" == $(__runc state test_busybox | jq '.pid') ]]
70}
View as plain text