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