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
# GIVEN a webserver with VIRTUAL_HOST set to web.bats
docker_clean bats-web
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
prepare_web_container bats-web 80 -e VIRTUAL_HOST=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

View file

@ -62,7 +62,7 @@ load test_helpers
-v /etc/nginx/certs/ \
nginx:latest
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'
# 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" {
# WHEN a container runs a web server with VIRTUAL_HOST set for multiple hosts
docker_clean bats-multiple-hosts-1
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'
prepare_web_container bats-multiple-hosts-1 80 -e VIRTUAL_HOST=multiple-hosts-1-A.bats,multiple-hosts-1-B.bats
# THEN querying the proxy without Host header → 503
run curl_container $SUT_CONTAINER / --head
@ -38,10 +28,10 @@ function setup {
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
# THEN
run curl_container $SUT_CONTAINER / --head --header 'Host: multiple-hosts-1-A.bats'
assert_output -l 0 $'HTTP/1.1 200 OK\r' || (echo $output; echo $status; false)
run curl_container $SUT_CONTAINER /data --header 'Host: multiple-hosts-1-A.bats'
assert_output "answer from port 80"
# THEN
run curl_container $SUT_CONTAINER / --head --header 'Host: multiple-hosts-1-B.bats'
assert_output -l 0 $'HTTP/1.1 200 OK\r'
run curl_container $SUT_CONTAINER /data --header 'Host: multiple-hosts-1-B.bats'
assert_output "answer from port 80"
}