Skip to content

Commit

Permalink
add tests for env param in hooks
Browse files Browse the repository at this point in the history
Signed-off-by: lfbzhm <[email protected]>
  • Loading branch information
lifubang committed Jun 19, 2024
1 parent c9dcc3d commit d3908aa
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/integration/hooks.bats
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,44 @@ function teardown() {
[[ "$output" == *"error running $hook hook #1:"* ]]
done
}

@test "runc run [hook with env]" {
update_config '.process.args = ["/bin/true"]'
# All hooks except Poststop.
for hook in prestart createRuntime createContainer startContainer poststart; do
echo "testing hook $hook"
set mm=nn

Check warning on line 51 in tests/integration/hooks.bats

View workflow job for this annotation

GitHub Actions / shellcheck

To assign a variable, use just 'var=value', no 'set ..'.
# shellcheck disable=SC2016
update_config '.hooks = {
"'$hook'": [{
"path": "/bin/sh",
"args": [ "/bin/sh", "-c", "[ \"$mm\"==\"tt\" ] && echo yes, we got tt from the env mm && exit 1 || exit 0" ],
"env": [ "mm=tt" ]
}]
}'
runc run "test_hook-$hook"
unset mm
[ "$status" -ne 0 ]
[[ "$output" == *"yes, we got tt from the env mm"* ]]
done
}

@test "runc run [hook without env]" {
update_config '.process.args = ["/bin/true"]'
# All hooks except Poststop.
for hook in prestart createRuntime createContainer startContainer poststart; do
echo "testing hook $hook"
set mm=nn

Check warning on line 72 in tests/integration/hooks.bats

View workflow job for this annotation

GitHub Actions / shellcheck

To assign a variable, use just 'var=value', no 'set ..'.
# shellcheck disable=SC2016
update_config '.hooks = {
"'$hook'": [{
"path": "/bin/sh",
"args": [ "/bin/sh", "-c", "[ \"$mm\"==\"nn\" ] && echo we should set the env mm in runc config && exit 1 || exit 0" ]
}]
}'
runc run "test_hook-$hook"
unset mm
[ "$status" -ne 0 ]
[[ "$output" == *"we should set the env mm in runc config"* ]]
done
}

0 comments on commit d3908aa

Please sign in to comment.