1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2024-11-22 11:56:31 +00:00

tests: refactoring

This commit is contained in:
Thomas LEVEIL 2015-09-30 23:40:04 +00:00
parent 4bd30f5d2c
commit b4d1acbf2d
3 changed files with 7 additions and 26 deletions

View File

@ -12,16 +12,7 @@ function setup {
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-1 SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-1
# GIVEN a webserver with VIRTUAL_HOST set to web.bats # GIVEN a webserver with VIRTUAL_HOST set to web.bats
docker_clean bats-web prepare_web_container bats-web 80 -e VIRTUAL_HOST=web.bats
run docker run -d \
--label bats-type="web" \
--name bats-web \
-e VIRTUAL_HOST=web.bats \
--expose 80 \
-w /var/www \
python:3 \
python -m http.server 80
assert_success
# WHEN nginx-proxy runs with DEFAULT_HOST set to web.bats # WHEN nginx-proxy runs with DEFAULT_HOST set to web.bats
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro -e DEFAULT_HOST=web.bats run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro -e DEFAULT_HOST=web.bats

View File

@ -62,7 +62,7 @@ load test_helpers
-v /etc/nginx/certs/ \ -v /etc/nginx/certs/ \
nginx:latest nginx:latest
assert_success assert_success
run retry 5 1s curl --silent --fail -A "before-docker-gen" --head http://$(docker_ip bats-nginx)/ run retry 5 1s curl --silent --fail --head http://$(docker_ip bats-nginx)/
assert_output -l 0 $'HTTP/1.1 200 OK\r' assert_output -l 0 $'HTTP/1.1 200 OK\r'
# WHEN docker-gen runs on our docker host # WHEN docker-gen runs on our docker host

View File

@ -17,17 +17,7 @@ function setup {
@test "[$TEST_FILE] nginx-proxy forwards requests for 2 hosts" { @test "[$TEST_FILE] nginx-proxy forwards requests for 2 hosts" {
# WHEN a container runs a web server with VIRTUAL_HOST set for multiple hosts # WHEN a container runs a web server with VIRTUAL_HOST set for multiple hosts
docker_clean bats-multiple-hosts-1 prepare_web_container bats-multiple-hosts-1 80 -e VIRTUAL_HOST=multiple-hosts-1-A.bats,multiple-hosts-1-B.bats
run docker run -d \
--label bats-type="web" \
--name bats-multiple-hosts-1 \
-e VIRTUAL_HOST=multiple-hosts-1-A.bats,multiple-hosts-1-B.bats \
--expose 80 \
-w /data \
python:3 python -m http.server 80
assert_success
run retry 5 1s curl_container bats-multiple-hosts-1 / --head
assert_output -l 0 $'HTTP/1.0 200 OK\r'
# THEN querying the proxy without Host header → 503 # THEN querying the proxy without Host header → 503
run curl_container $SUT_CONTAINER / --head run curl_container $SUT_CONTAINER / --head
@ -38,10 +28,10 @@ function setup {
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r' assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
# THEN # THEN
run curl_container $SUT_CONTAINER / --head --header 'Host: multiple-hosts-1-A.bats' run curl_container $SUT_CONTAINER /data --header 'Host: multiple-hosts-1-A.bats'
assert_output -l 0 $'HTTP/1.1 200 OK\r' || (echo $output; echo $status; false) assert_output "answer from port 80"
# THEN # THEN
run curl_container $SUT_CONTAINER / --head --header 'Host: multiple-hosts-1-B.bats' run curl_container $SUT_CONTAINER /data --header 'Host: multiple-hosts-1-B.bats'
assert_output -l 0 $'HTTP/1.1 200 OK\r' assert_output "answer from port 80"
} }