|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ably.types.options import Options |
| 4 | + |
| 5 | + |
| 6 | +def test_options_should_fail_early_with_incompatible_client_options(): |
| 7 | + with pytest.raises(ValueError): |
| 8 | + Options(endpoint="foo", environment="foo") |
| 9 | + |
| 10 | + with pytest.raises(ValueError): |
| 11 | + Options(endpoint="foo", rest_host="foo") |
| 12 | + |
| 13 | + with pytest.raises(ValueError): |
| 14 | + Options(endpoint="foo", realtime_host="foo") |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +# REC1a |
| 19 | +def test_options_should_return_the_default_hostnames(): |
| 20 | + opts = Options() |
| 21 | + assert opts.get_realtime_host() == "main.realtime.ably.net" |
| 22 | + assert "main.a.fallback.ably-realtime.com" in opts.get_fallback_realtime_hosts() |
| 23 | + |
| 24 | + |
| 25 | +# REC1b4 |
| 26 | +def test_options_should_return_the_correct_routing_policy_hostnames(): |
| 27 | + opts = Options(endpoint="foo") |
| 28 | + assert opts.get_realtime_host() == "foo.realtime.ably.net" |
| 29 | + assert "foo.a.fallback.ably-realtime.com" in opts.get_fallback_realtime_hosts() |
| 30 | + |
| 31 | + |
| 32 | +# REC1b3 |
| 33 | +def test_options_should_return_the_correct_nonprod_routing_policy_hostnames(): |
| 34 | + opts = Options(endpoint="nonprod:foo") |
| 35 | + assert opts.get_realtime_host() == "foo.realtime.ably-nonprod.net" |
| 36 | + assert "foo.a.fallback.ably-realtime-nonprod.com" in opts.get_fallback_realtime_hosts() |
| 37 | + |
| 38 | + |
| 39 | +# REC1b2 |
| 40 | +def test_options_should_return_the_correct_fqdn_hostnames(): |
| 41 | + opts = Options(endpoint="foo.com") |
| 42 | + assert opts.get_realtime_host() == "foo.com" |
| 43 | + assert not opts.get_fallback_realtime_hosts() |
| 44 | + |
| 45 | + |
| 46 | +# REC1b2 |
| 47 | +def test_options_should_return_an_ipv4_address(): |
| 48 | + opts = Options(endpoint="127.0.0.1") |
| 49 | + assert opts.get_realtime_host() == "127.0.0.1" |
| 50 | + assert not opts.get_fallback_realtime_hosts() |
| 51 | + |
| 52 | + |
| 53 | +# REC1b2 |
| 54 | +def test_options_should_return_an_ipv6_address(): |
| 55 | + opts = Options(endpoint="::1") |
| 56 | + assert opts.get_realtime_host() == "::1" |
| 57 | + |
| 58 | + |
| 59 | +# REC1b2 |
| 60 | +def test_options_should_return_localhost(): |
| 61 | + opts = Options(endpoint="localhost") |
| 62 | + assert opts.get_realtime_host() == "localhost" |
0 commit comments