Skip to content

Commit 5fe9411

Browse files
committed
Change line endings to Unix
1 parent df6778f commit 5fe9411

File tree

2 files changed

+122
-122
lines changed

2 files changed

+122
-122
lines changed

test/multiple-ports.bats

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
#!/usr/bin/env bats
2-
load test_helpers
3-
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
4-
5-
function setup {
6-
# make sure to stop any web container before each test so we don't
7-
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
8-
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
9-
}
10-
11-
12-
@test "[$TEST_FILE] start a nginx-proxy container" {
13-
# GIVEN nginx-proxy
14-
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
15-
assert_success
16-
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
17-
}
18-
19-
20-
@test "[$TEST_FILE] nginx-proxy defaults to the service running on port 80" {
21-
# WHEN
22-
prepare_web_container bats-web-${TEST_FILE}-1 "80 90" -e VIRTUAL_HOST=web.bats
23-
24-
# THEN
25-
assert_response_is_from_port 80
26-
}
27-
28-
29-
@test "[$TEST_FILE] VIRTUAL_PORT=90 while port 80 is also exposed" {
30-
# GIVEN
31-
prepare_web_container bats-web-${TEST_FILE}-2 "80 90" -e VIRTUAL_HOST=web.bats -e VIRTUAL_PORT=90
32-
33-
# THEN
34-
assert_response_is_from_port 90
35-
}
36-
37-
38-
@test "[$TEST_FILE] single exposed port != 80" {
39-
# GIVEN
40-
prepare_web_container bats-web-${TEST_FILE}-3 1234 -e VIRTUAL_HOST=web.bats
41-
42-
# THEN
43-
assert_response_is_from_port 1234
44-
}
45-
46-
47-
# assert querying nginx-proxy provides a response from the expected port of the web container
48-
# $1 port we are expecting an response from
49-
function assert_response_is_from_port {
50-
local -r port=$1
51-
run curl_container $SUT_CONTAINER /data --header "Host: web.bats"
52-
assert_output "answer from port $port"
53-
}
54-
1+
#!/usr/bin/env bats
2+
load test_helpers
3+
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
4+
5+
function setup {
6+
# make sure to stop any web container before each test so we don't
7+
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
8+
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
9+
}
10+
11+
12+
@test "[$TEST_FILE] start a nginx-proxy container" {
13+
# GIVEN nginx-proxy
14+
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
15+
assert_success
16+
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
17+
}
18+
19+
20+
@test "[$TEST_FILE] nginx-proxy defaults to the service running on port 80" {
21+
# WHEN
22+
prepare_web_container bats-web-${TEST_FILE}-1 "80 90" -e VIRTUAL_HOST=web.bats
23+
24+
# THEN
25+
assert_response_is_from_port 80
26+
}
27+
28+
29+
@test "[$TEST_FILE] VIRTUAL_PORT=90 while port 80 is also exposed" {
30+
# GIVEN
31+
prepare_web_container bats-web-${TEST_FILE}-2 "80 90" -e VIRTUAL_HOST=web.bats -e VIRTUAL_PORT=90
32+
33+
# THEN
34+
assert_response_is_from_port 90
35+
}
36+
37+
38+
@test "[$TEST_FILE] single exposed port != 80" {
39+
# GIVEN
40+
prepare_web_container bats-web-${TEST_FILE}-3 1234 -e VIRTUAL_HOST=web.bats
41+
42+
# THEN
43+
assert_response_is_from_port 1234
44+
}
45+
46+
47+
# assert querying nginx-proxy provides a response from the expected port of the web container
48+
# $1 port we are expecting an response from
49+
function assert_response_is_from_port {
50+
local -r port=$1
51+
run curl_container $SUT_CONTAINER /data --header "Host: web.bats"
52+
assert_output "answer from port $port"
53+
}
54+

test/wildcard-hosts.bats

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
1-
#!/usr/bin/env bats
2-
load test_helpers
3-
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
4-
5-
function setup {
6-
# make sure to stop any web container before each test so we don't
7-
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
8-
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
9-
}
10-
11-
12-
@test "[$TEST_FILE] start a nginx-proxy container" {
13-
# GIVEN
14-
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
15-
assert_success
16-
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
17-
}
18-
19-
20-
@test "[$TEST_FILE] VIRTUAL_HOST=*.wildcard.bats" {
21-
# WHEN
22-
prepare_web_container bats-wildcard-hosts-1 80 -e VIRTUAL_HOST=*.wildcard.bats
23-
24-
# THEN
25-
assert_200 f00.wildcard.bats
26-
assert_200 bar.wildcard.bats
27-
assert_503 unexpected.host.bats
28-
}
29-
30-
@test "[$TEST_FILE] VIRTUAL_HOST=wildcard.bats.*" {
31-
# WHEN
32-
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=wildcard.bats.*
33-
34-
# THEN
35-
assert_200 wildcard.bats.f00
36-
assert_200 wildcard.bats.bar
37-
assert_503 unexpected.host.bats
38-
}
39-
40-
@test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats" {
41-
# WHEN
42-
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats
43-
44-
# THEN
45-
assert_200 foo.bar.whatever.bats
46-
assert_200 foo.bar.why.not.bats
47-
assert_503 unexpected.host.bats
48-
49-
}
50-
51-
52-
# assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response
53-
# $1 Host HTTP header to use when querying nginx-proxy
54-
function assert_200 {
55-
local -r host=$1
56-
57-
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
58-
assert_output -l 0 $'HTTP/1.1 200 OK\r'
59-
}
60-
61-
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
62-
# $1 Host HTTP header to use when querying nginx-proxy
63-
function assert_503 {
64-
local -r host=$1
65-
66-
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
67-
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
68-
}
1+
#!/usr/bin/env bats
2+
load test_helpers
3+
SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}
4+
5+
function setup {
6+
# make sure to stop any web container before each test so we don't
7+
# have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
8+
docker ps -q --filter "label=bats-type=web" | xargs -r docker stop >&2
9+
}
10+
11+
12+
@test "[$TEST_FILE] start a nginx-proxy container" {
13+
# GIVEN
14+
run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro
15+
assert_success
16+
docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
17+
}
18+
19+
20+
@test "[$TEST_FILE] VIRTUAL_HOST=*.wildcard.bats" {
21+
# WHEN
22+
prepare_web_container bats-wildcard-hosts-1 80 -e VIRTUAL_HOST=*.wildcard.bats
23+
24+
# THEN
25+
assert_200 f00.wildcard.bats
26+
assert_200 bar.wildcard.bats
27+
assert_503 unexpected.host.bats
28+
}
29+
30+
@test "[$TEST_FILE] VIRTUAL_HOST=wildcard.bats.*" {
31+
# WHEN
32+
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=wildcard.bats.*
33+
34+
# THEN
35+
assert_200 wildcard.bats.f00
36+
assert_200 wildcard.bats.bar
37+
assert_503 unexpected.host.bats
38+
}
39+
40+
@test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats" {
41+
# WHEN
42+
prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats
43+
44+
# THEN
45+
assert_200 foo.bar.whatever.bats
46+
assert_200 foo.bar.why.not.bats
47+
assert_503 unexpected.host.bats
48+
49+
}
50+
51+
52+
# assert that querying nginx-proxy with the given Host header produces a `HTTP 200` response
53+
# $1 Host HTTP header to use when querying nginx-proxy
54+
function assert_200 {
55+
local -r host=$1
56+
57+
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
58+
assert_output -l 0 $'HTTP/1.1 200 OK\r'
59+
}
60+
61+
# assert that querying nginx-proxy with the given Host header produces a `HTTP 503` response
62+
# $1 Host HTTP header to use when querying nginx-proxy
63+
function assert_503 {
64+
local -r host=$1
65+
66+
run curl_container $SUT_CONTAINER / --head --header "Host: $host"
67+
assert_output -l 0 $'HTTP/1.1 503 Service Temporarily Unavailable\r'
68+
}

0 commit comments

Comments
 (0)