default-host.bats 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. CIDS=( $(docker ps -q --filter "label=bats-type=web") )
  7. if [ ${#CIDS[@]} -gt 0 ]; then
  8. docker stop ${CIDS[@]} >&2
  9. fi
  10. }
  11. @test "[$TEST_FILE] DEFAULT_HOST=web1.bats" {
  12. SUT_CONTAINER=bats-nginx-proxy-${TEST_FILE}-1
  13. # GIVEN a webserver with VIRTUAL_HOST set to web.bats
  14. prepare_web_container bats-web 80 -e VIRTUAL_HOST=web.bats
  15. # WHEN nginx-proxy runs with DEFAULT_HOST set to web.bats
  16. run nginxproxy $SUT_CONTAINER -v /var/run/docker.sock:/tmp/docker.sock:ro -e DEFAULT_HOST=web.bats
  17. assert_success
  18. docker_wait_for_log $SUT_CONTAINER 3 "Watching docker events"
  19. # THEN querying the proxy without Host header → 200
  20. run curl_container $SUT_CONTAINER / --head
  21. assert_output -l 0 $'HTTP/1.1 200 OK\r'
  22. # THEN querying the proxy with any other Host header → 200
  23. run curl_container $SUT_CONTAINER / --head --header "Host: something.I.just.made.up"
  24. assert_output -l 0 $'HTTP/1.1 200 OK\r'
  25. }