图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

  1. from unittest import TestCase
  2. from kazoo.hosts import collect_hosts
  3. class HostsTestCase(TestCase):
  4. def test_ipv4(self):
  5. hosts, chroot = collect_hosts(
  6. "127.0.0.1:2181, 192.168.1.2:2181, \
  7. 132.254.111.10:2181"
  8. )
  9. assert hosts == [
  10. ("127.0.0.1", 2181),
  11. ("192.168.1.2", 2181),
  12. ("132.254.111.10", 2181),
  13. ]
  14. assert chroot is None
  15. hosts, chroot = collect_hosts(
  16. ["127.0.0.1:2181", "192.168.1.2:2181", "132.254.111.10:2181"]
  17. )
  18. assert hosts == [
  19. ("127.0.0.1", 2181),
  20. ("192.168.1.2", 2181),
  21. ("132.254.111.10", 2181),
  22. ]
  23. assert chroot is None
  24. def test_ipv6(self):
  25. hosts, chroot = collect_hosts("[fe80::200:5aee:feaa:20a2]:2181")
  26. assert hosts == [("fe80::200:5aee:feaa:20a2", 2181)]
  27. assert chroot is None
  28. hosts, chroot = collect_hosts(["[fe80::200:5aee:feaa:20a2]:2181"])
  29. assert hosts == [("fe80::200:5aee:feaa:20a2", 2181)]
  30. assert chroot is None
  31. def test_hosts_list(self):
  32. hosts, chroot = collect_hosts("zk01:2181, zk02:2181, zk03:2181")
  33. expected1 = [("zk01", 2181), ("zk02", 2181), ("zk03", 2181)]
  34. assert hosts == expected1
  35. assert chroot is None
  36. hosts, chroot = collect_hosts(["zk01:2181", "zk02:2181", "zk03:2181"])
  37. assert hosts == expected1
  38. assert chroot is None
  39. expected2 = "/test"
  40. hosts, chroot = collect_hosts("zk01:2181, zk02:2181, zk03:2181/test")
  41. assert hosts == expected1
  42. assert chroot == expected2
  43. hosts, chroot = collect_hosts(
  44. ["zk01:2181", "zk02:2181", "zk03:2181", "/test"]
  45. )
  46. assert hosts == expected1
  47. assert chroot == expected2