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 update_config ' (.. | select(.uid? == 0)) .uid |= 1000 30 | (.. | select(.gid? == 0)) .gid |= 100' 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 update_config '(.. | select(. == "rootfs")) |= "."' 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 [[ "$(cat pid.txt)" =~ [0-9]+ ]] 62} 63