github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/tests/integration/hooks.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  function setup() {
     6  	setup_busybox
     7  }
     8  
     9  function teardown() {
    10  	teardown_bundle
    11  }
    12  
    13  @test "runc create [second createRuntime hook fails]" {
    14  	update_config '.hooks |= {"createRuntime": [{"path": "/bin/true"}, {"path": "/bin/false"}]}'
    15  
    16  	runc create --console-socket "$CONSOLE_SOCKET" test_hooks
    17  	[ "$status" -ne 0 ]
    18  	[[ "$output" == *"error running createRuntime hook #1:"* ]]
    19  }
    20  
    21  @test "runc create [hook fails]" {
    22  	for hook in prestart createRuntime createContainer; do
    23  		echo "testing hook $hook"
    24  		# shellcheck disable=SC2016
    25  		update_config '.hooks |= {"'$hook'": [{"path": "/bin/true"}, {"path": "/bin/false"}]}'
    26  		runc create --console-socket "$CONSOLE_SOCKET" test_hooks
    27  		[ "$status" -ne 0 ]
    28  		[[ "$output" == *"error running $hook hook #1:"* ]]
    29  	done
    30  }
    31  
    32  @test "runc run [hook fails]" {
    33  	update_config '.process.args = ["/bin/echo", "Hello World"]'
    34  	# All hooks except Poststop.
    35  	for hook in prestart createRuntime createContainer startContainer poststart; do
    36  		echo "testing hook $hook"
    37  		# shellcheck disable=SC2016
    38  		update_config '.hooks |= {"'$hook'": [{"path": "/bin/true"}, {"path": "/bin/false"}]}'
    39  		runc run "test_hook-$hook"
    40  		[[ "$output" != "Hello World" ]]
    41  		[ "$status" -ne 0 ]
    42  		[[ "$output" == *"error running $hook hook #1:"* ]]
    43  	done
    44  }