Skip to content

Commit d3908aa

Browse files
committed
add tests for env param in hooks
Signed-off-by: lfbzhm <[email protected]>
1 parent c9dcc3d commit d3908aa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/integration/hooks.bats

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,44 @@ function teardown() {
4242
[[ "$output" == *"error running $hook hook #1:"* ]]
4343
done
4444
}
45+
46+
@test "runc run [hook with env]" {
47+
update_config '.process.args = ["/bin/true"]'
48+
# All hooks except Poststop.
49+
for hook in prestart createRuntime createContainer startContainer poststart; do
50+
echo "testing hook $hook"
51+
set mm=nn
52+
# shellcheck disable=SC2016
53+
update_config '.hooks = {
54+
"'$hook'": [{
55+
"path": "/bin/sh",
56+
"args": [ "/bin/sh", "-c", "[ \"$mm\"==\"tt\" ] && echo yes, we got tt from the env mm && exit 1 || exit 0" ],
57+
"env": [ "mm=tt" ]
58+
}]
59+
}'
60+
runc run "test_hook-$hook"
61+
unset mm
62+
[ "$status" -ne 0 ]
63+
[[ "$output" == *"yes, we got tt from the env mm"* ]]
64+
done
65+
}
66+
67+
@test "runc run [hook without env]" {
68+
update_config '.process.args = ["/bin/true"]'
69+
# All hooks except Poststop.
70+
for hook in prestart createRuntime createContainer startContainer poststart; do
71+
echo "testing hook $hook"
72+
set mm=nn
73+
# shellcheck disable=SC2016
74+
update_config '.hooks = {
75+
"'$hook'": [{
76+
"path": "/bin/sh",
77+
"args": [ "/bin/sh", "-c", "[ \"$mm\"==\"nn\" ] && echo we should set the env mm in runc config && exit 1 || exit 0" ]
78+
}]
79+
}'
80+
runc run "test_hook-$hook"
81+
unset mm
82+
[ "$status" -ne 0 ]
83+
[[ "$output" == *"we should set the env mm in runc config"* ]]
84+
done
85+
}

0 commit comments

Comments
 (0)