@@ -42,3 +42,41 @@ 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+ update_config ' .process.env = ["mm=nn"]'
49+ # All hooks except Poststop.
50+ for hook in prestart createRuntime createContainer startContainer poststart; do
51+ echo " testing hook $hook "
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+ mm=nn runc run " test_hook-$hook "
61+ [ " $status " -ne 0 ]
62+ [[ " $output " == * " yes, we got tt from the env mm" * ]]
63+ done
64+ }
65+
66+ @test " runc run [hook without env]" {
67+ update_config ' .process.args = ["/bin/true"]'
68+ update_config ' .process.env = ["mm=nn"]'
69+ # All hooks except Poststop.
70+ for hook in prestart createRuntime createContainer startContainer poststart; do
71+ echo " testing hook $hook "
72+ # shellcheck disable=SC2016
73+ update_config ' .hooks = {
74+ "' $hook ' ": [{
75+ "path": "/bin/sh",
76+ "args": ["/bin/sh", "-c", "[[ \"$mm\" == \"nn\" ]] && echo \"$mm\" && exit 1 || exit 0"]
77+ }]
78+ }'
79+ mm=nn runc run " test_hook-$hook "
80+ [ " $status " -eq 0 ]
81+ done
82+ }
0 commit comments