50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import unittest
|
|
|
|
from dns_sync.config import parse_endpoint_list
|
|
|
|
|
|
class EndpointParsingTests(unittest.TestCase):
|
|
def test_comma_separated_addresses_use_default_port(self):
|
|
endpoints = parse_endpoint_list(
|
|
"npm",
|
|
"192.168.1.3, 192.168.1.4:8081,192.168.1.5",
|
|
81,
|
|
)
|
|
|
|
self.assertEqual(
|
|
tuple(endpoint.identity for endpoint in endpoints),
|
|
(
|
|
"npm://192.168.1.3:81",
|
|
"npm://192.168.1.4:8081",
|
|
"npm://192.168.1.5:81",
|
|
),
|
|
)
|
|
|
|
def test_duplicate_is_rejected_after_normalization(self):
|
|
with self.assertRaisesRegex(RuntimeError, "Duplicate NPM"):
|
|
parse_endpoint_list(
|
|
"npm",
|
|
"192.168.1.3,192.168.1.3:81",
|
|
81,
|
|
)
|
|
|
|
def test_empty_entry_is_rejected(self):
|
|
with self.assertRaisesRegex(RuntimeError, "empty address"):
|
|
parse_endpoint_list(
|
|
"npm",
|
|
"192.168.1.3,,192.168.1.5",
|
|
81,
|
|
)
|
|
|
|
def test_url_scheme_is_rejected(self):
|
|
with self.assertRaisesRegex(RuntimeError, "must not include"):
|
|
parse_endpoint_list(
|
|
"npm",
|
|
"http://192.168.1.3:81",
|
|
81,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|