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

Change line endings to Unix

This commit is contained in:
Mike Dillon 2015-10-09 23:07:46 -07:00
parent df6778f673
commit 5fe9411d88
2 changed files with 122 additions and 122 deletions

View File

@ -1,54 +1,54 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load test_helpers load test_helpers
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE} SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
function setup { function setup {
# make sure to stop any web container before each test so we don't # make sure to stop any web container before each test so we don't
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set # have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2 docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
} }
@test "[$TEST_FILE] start a nginx-proxy container" { @test "[$TEST_FILE] start a nginx-proxy container" {
# GIVEN nginx-proxy # GIVEN nginx-proxy
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
assert_success assert_success
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events" docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
} }
@test "[$TEST_FILE] nginx-proxy defaults to the service running on port 80" { @test "[$TEST_FILE] nginx-proxy defaults to the service running on port 80" {
# WHEN # WHEN
prepare_web_container bats-web-${TEST_FILE}-1 "80 90" -e VIRTUAL_HOST=web.bats prepare_web_container bats-web-${TEST_FILE}-1 "80 90" -e VIRTUAL_HOST=web.bats
# THEN # THEN
assert_response_is_from_port 80 assert_response_is_from_port 80
} }
@test "[$TEST_FILE] VIRTUAL_PORT=90 while port 80 is also exposed" { @test "[$TEST_FILE] VIRTUAL_PORT=90 while port 80 is also exposed" {
# GIVEN # GIVEN
prepare_web_container bats-web-${TEST_FILE}-2 "80 90" -e VIRTUAL_HOST=web.bats -e VIRTUAL_PORT=90 prepare_web_container bats-web-${TEST_FILE}-2 "80 90" -e VIRTUAL_HOST=web.bats -e VIRTUAL_PORT=90
# THEN # THEN
assert_response_is_from_port 90 assert_response_is_from_port 90
} }
@test "[$TEST_FILE] single exposed port != 80" { @test "[$TEST_FILE] single exposed port != 80" {
# GIVEN # GIVEN
prepare_web_container bats-web-${TEST_FILE}-3 1234 -e VIRTUAL_HOST=web.bats prepare_web_container bats-web-${TEST_FILE}-3 1234 -e VIRTUAL_HOST=web.bats
# THEN # THEN
assert_response_is_from_port 1234 assert_response_is_from_port 1234
} }
# assert querying nginx-proxy provides a response from the expected port of the web container # assert querying nginx-proxy provides a response from the expected port of the web container
# $1 port we are expecting an response from # $1 port we are expecting an response from
function assert_response_is_from_port { function assert_response_is_from_port {
local -r port=$1 local -r port=$1
run curl_container $SUT_CONTAINER /data --header "Host: web.bats" run curl_container $SUT_CONTAINER /data --header "Host: web.bats"
assert_output "answer from port $port" assert_output "answer from port $port"
} }

View File

@ -1,68 +1,68 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load test_helpers load test_helpers
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE} SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
function setup { function setup {
# make sure to stop any web container before each test so we don't # make sure to stop any web container before each test so we don't
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set # have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2 docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
} }
@test "[$TEST_FILE] start a nginx-proxy container" { @test "[$TEST_FILE] start a nginx-proxy container" {
# GIVEN # GIVEN
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
assert_success assert_success
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events" docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
} }
@test "[$TEST_FILE] VIRTUAL_HOST=*.wildcard.bats" { @test "[$TEST_FILE] VIRTUAL_HOST=*.wildcard.bats" {
# WHEN # WHEN
prepare_web_container bats-wildcard-hosts-1 80 -e VIRTUAL_HOST=*.wildcard.bats prepare_web_container bats-wildcard-hosts-1 80 -e VIRTUAL_HOST=*.wildcard.bats
# THEN # THEN
assert_200 f00.wildcard.bats assert_200 f00.wildcard.bats
assert_200 bar.wildcard.bats assert_200 bar.wildcard.bats
assert_503 unexpected.host.bats assert_503 unexpected.host.bats
} }
@test "[$TEST_FILE] VIRTUAL_HOST=wildcard.bats.*" { @test "[$TEST_FILE] VIRTUAL_HOST=wildcard.bats.*" {
# WHEN # WHEN
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=wildcard.bats.* prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=wildcard.bats.*
# THEN # THEN
assert_200 wildcard.bats.f00 assert_200 wildcard.bats.f00
assert_200 wildcard.bats.bar assert_200 wildcard.bats.bar
assert_503 unexpected.host.bats assert_503 unexpected.host.bats
} }
@test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats" { @test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats" {
# WHEN # WHEN
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats
# THEN # THEN
assert_200 foo.bar.whatever.bats assert_200 foo.bar.whatever.bats
assert_200 foo.bar.why.not.bats assert_200 foo.bar.why.not.bats
assert_503 unexpected.host.bats assert_503 unexpected.host.bats
} }
# assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response # assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response
# $1 Host HTTP header to use when querying nginx-proxy # $1 Host HTTP header to use when querying nginx-proxy
function assert_200 { function assert_200 {
local -r host=$1 local -r host=$1
run curl_container $SUT_CONTAINER / --head --header "Host: $host" run curl_container $SUT_CONTAINER / --head --header "Host: $host"
assert_output -l 0 $'HTTP/1.1 200 OK\r' assert_output -l 0 $'HTTP/1.1 200 OK\r'
} }
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response # assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
# $1 Host HTTP header to use when querying nginx-proxy # $1 Host HTTP header to use when querying nginx-proxy
function assert_503 { function assert_503 {
local -r host=$1 local -r host=$1
run curl_container $SUT_CONTAINER / --head --header "Host: $host" run curl_container $SUT_CONTAINER / --head --header "Host: $host"
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r' assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
} }