1#!/usr/bin/env bats
2
3load helpers
4
5function setup() {
6  teardown_hello
7  setup_hello
8}
9
10function teardown() {
11  teardown_hello
12}
13
14@test "runc run" {
15  # run hello-world
16  runc run test_hello
17  [ "$status" -eq 0 ]
18
19  # check expected output
20  [[ "${output}" == *"Hello"* ]]
21}
22
23@test "runc run ({u,g}id != 0)" {
24  # cannot start containers as another user in rootless setup without idmap
25  [[ "$ROOTLESS" -ne 0 ]] && requires rootless_idmap
26
27  # replace "uid": 0 with "uid": 1000
28  # and do a similar thing for gid.
29  sed -i 's;"uid": 0;"uid": 1000;g' config.json
30  sed -i 's;"gid": 0;"gid": 100;g' config.json
31
32  # run hello-world
33  runc run test_hello
34  [ "$status" -eq 0 ]
35
36  # check expected output
37  [[ "${output}" == *"Hello"* ]]
38}
39
40@test "runc run with rootfs set to ." {
41  cp config.json rootfs/.
42  rm config.json
43  cd rootfs
44  sed -i 's;"rootfs";".";' config.json
45
46  # run hello-world
47  runc run test_hello
48  [ "$status" -eq 0 ]
49  [[ "${output}" == *"Hello"* ]]
50}
51
52@test "runc run --pid-file" {
53  # run hello-world
54  runc run --pid-file pid.txt test_hello
55  [ "$status" -eq 0 ]
56  [[ "${output}" == *"Hello"* ]]
57
58  # check pid.txt was generated
59  [ -e pid.txt ]
60
61  run cat pid.txt
62  [ "$status" -eq 0 ]
63  [[ ${lines[0]} =~ [0-9]+ ]]
64}
65