2
0

default-host.bats 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bats
  2. load test_helpers
  3. function setup {
  4. # make sure to stop any web container before each test so we don't
  5. # have any unexpected contaiener running with VIRTUAL_HOST or VIRUTAL_PORT set
  6. stop_bats_containers web
  7. }
  8. @test "[$TEST_FILE] DEFAULT_HOST=web1.bats" {
  9. SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-1
  10. # GIVEN a webserver with VIRTUAL_HOST set to web.bats
  11. prepare_web_container bats-web 80 -e VIRTUAL_HOST=web.bats
  12. # WHEN nginx-proxy runs with DEFAULT_HOST set to web.bats
  13. run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro -e DEFAULT_HOST=web.bats
  14. assert_success
  15. docker_wait_for_log $SUT_CONTAINER 9 "Watching docker events"
  16. # THEN querying the proxy without Host header → 200
  17. run curl_container $SUT_CONTAINER / --head
  18. assert_output -l 0 $'HTTP/1.1 200 OK\r'
  19. # THEN querying the proxy with any other Host header → 200
  20. run curl_container $SUT_CONTAINER / --head --header "Host: something.I.just.made.up"
  21. assert_output -l 0 $'HTTP/1.1 200 OK\r'
  22. }
  23. @test "[$TEST_FILE] stop all bats containers" {
  24. stop_bats_containers
  25. }