Skip to content

Commit 4fd8a7a

Browse files
committed
bats: refactor run "$RUNC" -> runc
This makes it much simpler to write tests, and you don't have to worry about some of the oddness with bats. Signed-off-by: Aleksa Sarai <asarai@suse.de>
1 parent 57b9972 commit 4fd8a7a

19 files changed

+140
-139
lines changed

tests/integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function teardown() {
7171
}
7272

7373
@test "this is a simple test" {
74-
run "$RUNC" start containerid
74+
runc start containerid
7575
# "run" automatically populates $status, $output and $lines.
7676
# Please refer to bats documentation to find out more.
7777
[ "$status" -eq 0 ]

tests/integration/cgroups.bats

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function teardown() {
1919
function setup() {
2020
teardown
2121
setup_busybox
22-
2322
init_cgroup_path
2423
}
2524

@@ -49,13 +48,15 @@ EOF
4948
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
5049

5150
# start a detached busybox to work with
52-
run "$RUNC" start -d --console /dev/pts/ptmx test_cgroups_kmem
51+
runc start -d --console /dev/pts/ptmx test_cgroups_kmem
5352
[ "$status" -eq 0 ]
5453
wait_for_container 15 1 test_cgroups_kmem
5554

5655
# update kernel memory limit
57-
run "$RUNC" update test_cgroups_kmem --kernel-memory 50331648
56+
runc update test_cgroups_kmem --kernel-memory 50331648
5857
[ "$status" -eq 0 ]
58+
59+
# check the value
5960
check_cgroup_value $CGROUP_MEMORY "memory.kmem.limit_in_bytes" 50331648
6061
}
6162

@@ -64,12 +65,12 @@ EOF
6465
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
6566

6667
# start a detached busybox to work with
67-
run "$RUNC" start -d --console /dev/pts/ptmx test_cgroups_kmem
68+
runc start -d --console /dev/pts/ptmx test_cgroups_kmem
6869
[ "$status" -eq 0 ]
6970
wait_for_container 15 1 test_cgroups_kmem
7071

7172
# update kernel memory limit
72-
run "$RUNC" update test_cgroups_kmem --kernel-memory 50331648
73+
runc update test_cgroups_kmem --kernel-memory 50331648
7374
# Since kernel 4.6, we can update kernel memory without initialization
7475
# because it's accounted by default.
7576
if [ "$KERNEL_MAJOR" -lt 4 ] || [ "$KERNEL_MAJOR" -eq 4 -a "$KERNEL_MINOR" -le 5 ]; then

tests/integration/checkpoint.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,38 @@ function teardown() {
2424

2525
(
2626
# start busybox (not detached)
27-
run "$RUNC" start test_busybox
27+
runc start test_busybox
2828
[ "$status" -eq 0 ]
2929
) &
3030

3131
# check state
3232
wait_for_container 15 1 test_busybox
3333

34-
run "$RUNC" state test_busybox
34+
runc state test_busybox
3535
[ "$status" -eq 0 ]
3636
[[ "${output}" == *"running"* ]]
3737

3838
# checkpoint the running container
39-
run "$RUNC" --criu "$CRIU" checkpoint test_busybox
39+
runc --criu "$CRIU" checkpoint test_busybox
4040
# if you are having problems getting criu to work uncomment the following dump:
4141
#cat /run/opencontainer/containers/test_busybox/criu.work/dump.log
4242
[ "$status" -eq 0 ]
4343

4444
# after checkpoint busybox is no longer running
45-
run "$RUNC" state test_busybox
45+
runc state test_busybox
4646
[ "$status" -ne 0 ]
4747

4848
# restore from checkpoint
4949
(
50-
run "$RUNC" --criu "$CRIU" restore test_busybox
50+
runc --criu "$CRIU" restore test_busybox
5151
[ "$status" -eq 0 ]
5252
) &
5353

5454
# check state
5555
wait_for_container 15 1 test_busybox
5656

5757
# busybox should be back up and running
58-
run "$RUNC" state test_busybox
58+
runc state test_busybox
5959
[ "$status" -eq 0 ]
6060
[[ "${output}" == *"running"* ]]
6161
}

tests/integration/debug.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ function teardown() {
1313

1414
@test "global --debug" {
1515
# start hello-world
16-
run "$RUNC" --debug start test_hello
16+
runc --debug start test_hello
1717
echo "${output}"
1818
[ "$status" -eq 0 ]
1919
}
2020

2121
@test "global --debug to --log" {
2222
# start hello-world
23-
run "$RUNC" --log log.out --debug start test_hello
23+
runc --log log.out --debug start test_hello
2424
[ "$status" -eq 0 ]
2525

2626
# check output does not include debug info
@@ -37,7 +37,7 @@ function teardown() {
3737

3838
@test "global --debug to --log --log-format 'text'" {
3939
# start hello-world
40-
run "$RUNC" --log log.out --log-format "text" --debug start test_hello
40+
runc --log log.out --log-format "text" --debug start test_hello
4141
[ "$status" -eq 0 ]
4242

4343
# check output does not include debug info
@@ -54,7 +54,7 @@ function teardown() {
5454

5555
@test "global --debug to --log --log-format 'json'" {
5656
# start hello-world
57-
run "$RUNC" --log log.out --log-format "json" --debug start test_hello
57+
runc --log log.out --log-format "json" --debug start test_hello
5858
[ "$status" -eq 0 ]
5959

6060
# check output does not include debug info

tests/integration/delete.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ function teardown() {
1313

1414
@test "runc delete" {
1515
# start busybox detached
16-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
16+
runc start -d --console /dev/pts/ptmx test_busybox
1717
[ "$status" -eq 0 ]
1818

1919
# check state
2020
wait_for_container 15 1 test_busybox
2121

2222
testcontainer test_busybox running
2323

24-
run "$RUNC" kill test_busybox KILL
24+
runc kill test_busybox KILL
2525
# wait for busybox to be in the destroyed state
26-
retry 10 1 eval "'$RUNC' state test_busybox | grep -q 'destroyed'"
26+
retry 10 1 eval "__runc state test_busybox | grep -q 'destroyed'"
2727

2828
# delete test_busybox
29-
run "$RUNC" delete test_busybox
29+
runc delete test_busybox
3030

31-
run "$RUNC" state test_busybox
31+
runc state test_busybox
3232
[ "$status" -ne 0 ]
3333
}

tests/integration/events.bats

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,24 @@ function teardown() {
1111
teardown_busybox
1212
}
1313

14-
function startup_events() {
15-
("$RUNC" events test_busybox > events.log)
16-
}
17-
1814
@test "events --stats" {
1915
# start busybox detached
20-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
16+
runc start -d --console /dev/pts/ptmx test_busybox
2117
[ "$status" -eq 0 ]
2218

2319
# check state
2420
wait_for_container 15 1 test_busybox
2521

2622
# generate stats
27-
run "$RUNC" events --stats test_busybox
23+
runc events --stats test_busybox
2824
[ "$status" -eq 0 ]
2925
[[ "${lines[0]}" == [\{]"\"type\""[:]"\"stats\""[,]"\"id\""[:]"\"test_busybox\""[,]* ]]
3026
[[ "${lines[0]}" == *"data"* ]]
3127
}
3228

3329
@test "events --interval default " {
3430
# start busybox detached
35-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
31+
runc start -d --console /dev/pts/ptmx test_busybox
3632
[ "$status" -eq 0 ]
3733

3834
# check state
@@ -42,7 +38,7 @@ function startup_events() {
4238
# the first sub process is an event logger that sends stats events to events.log
4339
# the second sub process waits for an event that incudes test_busybox then
4440
# kills the test_busybox container which causes the event logger to exit
45-
("$RUNC" events test_busybox > events.log) &
41+
(__runc events test_busybox > events.log) &
4642
(
4743
retry 10 1 eval "grep -q 'test_busybox' events.log"
4844
teardown_running_container test_busybox
@@ -59,7 +55,7 @@ function startup_events() {
5955

6056
@test "events --interval 1s " {
6157
# start busybox detached
62-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
58+
runc start -d --console /dev/pts/ptmx test_busybox
6359
[ "$status" -eq 0 ]
6460

6561
# check state
@@ -70,7 +66,7 @@ function startup_events() {
7066
# the second sub process tries 3 times for an event that incudes test_busybox
7167
# pausing 1s between each attempt then kills the test_busybox container which
7268
# causes the event logger to exit
73-
("$RUNC" events --interval 1s test_busybox > events.log) &
69+
(__runc events --interval 1s test_busybox > events.log) &
7470
(
7571
retry 3 1 eval "grep -q 'test_busybox' events.log"
7672
teardown_running_container test_busybox
@@ -85,7 +81,7 @@ function startup_events() {
8581

8682
@test "events --interval 100ms " {
8783
# start busybox detached
88-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
84+
runc start -d --console /dev/pts/ptmx test_busybox
8985
[ "$status" -eq 0 ]
9086

9187
# check state
@@ -99,7 +95,7 @@ function startup_events() {
9995
# the second sub process tries 3 times for an event that incudes test_busybox
10096
# pausing 100s between each attempt then kills the test_busybox container which
10197
# causes the event logger to exit
102-
("$RUNC" events --interval 100ms test_busybox > events.log) &
98+
(__runc events --interval 100ms test_busybox > events.log) &
10399
(
104100
retry 3 0.100 eval "grep -q 'test_busybox' events.log"
105101
teardown_running_container test_busybox

tests/integration/exec.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ function teardown() {
1313

1414
@test "runc exec" {
1515
# start busybox detached
16-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
16+
runc start -d --console /dev/pts/ptmx test_busybox
1717
[ "$status" -eq 0 ]
1818

1919
wait_for_container 15 1 test_busybox
2020

21-
run "$RUNC" exec test_busybox echo Hello from exec
21+
runc exec test_busybox echo Hello from exec
2222
[ "$status" -eq 0 ]
2323
echo text echoed = "'""${output}""'"
2424
[[ "${output}" == *"Hello from exec"* ]]
2525
}
2626

2727
@test "runc exec --pid-file" {
2828
# start busybox detached
29-
run "$RUNC" start -d --console /dev/pts/ptmx test_busybox
29+
runc start -d --console /dev/pts/ptmx test_busybox
3030
[ "$status" -eq 0 ]
3131

3232
wait_for_container 15 1 test_busybox
3333

34-
run "$RUNC" exec --pid-file pid.txt test_busybox echo Hello from exec
34+
runc exec --pid-file pid.txt test_busybox echo Hello from exec
3535
[ "$status" -eq 0 ]
3636
echo text echoed = "'""${output}""'"
3737
[[ "${output}" == *"Hello from exec"* ]]

tests/integration/help.bats

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,80 @@
33
load helpers
44

55
@test "runc -h" {
6-
run "$RUNC" -h
6+
runc -h
77
[ "$status" -eq 0 ]
88
[[ ${lines[0]} =~ NAME:+ ]]
99
[[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]]
1010

11-
run "$RUNC" --help
11+
runc --help
1212
[ "$status" -eq 0 ]
1313
[[ ${lines[0]} =~ NAME:+ ]]
1414
[[ ${lines[1]} =~ runc\ '-'\ Open\ Container\ Initiative\ runtime+ ]]
1515
}
1616

1717
@test "runc command -h" {
18-
run "$RUNC" checkpoint -h
18+
runc checkpoint -h
1919
[ "$status" -eq 0 ]
2020
[[ ${lines[1]} =~ runc\ checkpoint+ ]]
2121

22-
run "$RUNC" delete -h
22+
runc delete -h
2323
[ "$status" -eq 0 ]
2424
[[ ${lines[1]} =~ runc\ delete+ ]]
2525

26-
run "$RUNC" events -h
26+
runc events -h
2727
[ "$status" -eq 0 ]
2828
[[ ${lines[1]} =~ runc\ events+ ]]
2929

30-
run "$RUNC" exec -h
30+
runc exec -h
3131
[ "$status" -eq 0 ]
3232
[[ ${lines[1]} =~ runc\ exec+ ]]
3333

34-
run "$RUNC" kill -h
34+
runc kill -h
3535
[ "$status" -eq 0 ]
3636
[[ ${lines[1]} =~ runc\ kill+ ]]
3737

38-
run "$RUNC" list -h
38+
runc list -h
3939
[ "$status" -eq 0 ]
4040
[[ ${lines[0]} =~ NAME:+ ]]
4141
[[ ${lines[1]} =~ runc\ list+ ]]
4242

43-
run "$RUNC" list --help
43+
runc list --help
4444
[ "$status" -eq 0 ]
4545
[[ ${lines[0]} =~ NAME:+ ]]
4646
[[ ${lines[1]} =~ runc\ list+ ]]
4747

48-
run "$RUNC" pause -h
48+
runc pause -h
4949
[ "$status" -eq 0 ]
5050
[[ ${lines[1]} =~ runc\ pause+ ]]
5151

52-
run "$RUNC" restore -h
52+
runc restore -h
5353
[ "$status" -eq 0 ]
5454
[[ ${lines[1]} =~ runc\ restore+ ]]
5555

56-
run "$RUNC" resume -h
56+
runc resume -h
5757
[ "$status" -eq 0 ]
5858
[[ ${lines[1]} =~ runc\ resume+ ]]
5959

60-
run "$RUNC" spec -h
60+
runc spec -h
6161
[ "$status" -eq 0 ]
6262
[[ ${lines[1]} =~ runc\ spec+ ]]
6363

64-
run "$RUNC" start -h
64+
runc start -h
6565
[ "$status" -eq 0 ]
6666
[[ ${lines[1]} =~ runc\ start+ ]]
6767

68-
run "$RUNC" state -h
68+
runc state -h
6969
[ "$status" -eq 0 ]
7070
[[ ${lines[1]} =~ runc\ state+ ]]
7171

72-
run "$RUNC" delete -h
72+
runc delete -h
7373
[ "$status" -eq 0 ]
7474
[[ ${lines[1]} =~ runc\ delete+ ]]
7575

7676
}
7777

7878
@test "runc foo -h" {
79-
run "$RUNC" foo -h
79+
runc foo -h
8080
[ "$status" -ne 0 ]
8181
[[ "${output}" == *"No help topic for 'foo'"* ]]
8282
}

0 commit comments

Comments
 (0)