-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bats test for host network driver
Bats test asserts on both scenarios: - Binding a process port to 0.0.0.0 - Binding a process port to 127.0.0.1 Signed-off-by: Nino Kodabande <[email protected]>
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
load '../helpers/load' | ||
|
||
LOCALHOST="127.0.0.1" | ||
|
||
@test 'factory reset' { | ||
factory_reset | ||
} | ||
|
||
@test 'start container engine' { | ||
start_container_engine | ||
wait_for_container_engine | ||
} | ||
|
||
run_container_with_host_network_driver() { | ||
local image="python:slim" | ||
ctrctl pull "$image" | ||
ctrctl run -d --network=host --restart=no "$image" "$@" | ||
} | ||
|
||
verify_container_port() { | ||
run try --max 9 --delay 10 curl --insecure --verbose --show-error "$@" | ||
assert_success | ||
assert_output --partial 'Directory listing for' | ||
} | ||
|
||
@test 'process is bound to 0.0.0.0 using host network driver' { | ||
local container_port="8010" | ||
run_container_with_host_network_driver python -m http.server "$container_port" | ||
verify_container_port "http://$LOCALHOST:$container_port" | ||
skip_unless_host_ip | ||
verify_container_port "http://${HOST_IP}:$container_port" | ||
} | ||
|
||
@test 'process is bound to 127.0.0.1 using host network driver' { | ||
local container_port="8016" | ||
run_container_with_host_network_driver python -m http.server $container_port --bind "$LOCALHOST" | ||
verify_container_port "http://$LOCALHOST:$container_port" | ||
skip_unless_host_ip | ||
run curl --verbose --head "http://${HOST_IP}:$container_port" | ||
assert_output --partial "curl: (7) Failed to connect" | ||
} |