test_custom-conf.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import pytest
  2. def test_default_root_response(docker_compose, nginxproxy):
  3. r = nginxproxy.get("http://nginx-proxy.test/")
  4. assert r.status_code == 418
  5. @pytest.mark.parametrize("stub,header", [
  6. ("nginx-proxy.test/web1", "bar"),
  7. ("foo.nginx-proxy.test", "f00"),
  8. ])
  9. def test_custom_applies(docker_compose, nginxproxy, stub, header):
  10. r = nginxproxy.get(f"http://{stub}/port")
  11. assert r.status_code == 200
  12. assert "X-test" in r.headers
  13. assert header == r.headers["X-test"]
  14. @pytest.mark.parametrize("stub,code", [
  15. ("nginx-proxy.test/foo", 418),
  16. ("nginx-proxy.test/web2", 200),
  17. ("nginx-proxy.test/web3", 200),
  18. ("bar.nginx-proxy.test", 503),
  19. ])
  20. def test_custom_does_not_apply(docker_compose, nginxproxy, stub, code):
  21. r = nginxproxy.get(f"http://{stub}/port")
  22. assert r.status_code == code
  23. assert "X-test" not in r.headers
  24. @pytest.mark.parametrize("stub,port", [
  25. ("nginx-proxy.test/web1", 81),
  26. ("nginx-proxy.test/web2", 82),
  27. ("nginx-proxy.test/web3", 83),
  28. ("nginx-proxy.test/alt", 83),
  29. ])
  30. def test_alternate(docker_compose, nginxproxy, stub, port):
  31. r = nginxproxy.get(f"http://{stub}/port")
  32. assert r.status_code == 200
  33. assert r.text == f"answer from port {port}\n"