test_zeromq.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Test salt.utils.zeromq
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import zmq
  8. # Import Salt Testing libs
  9. from tests.support.unit import TestCase, skipIf
  10. from tests.support.mock import (
  11. patch,
  12. NO_MOCK,
  13. NO_MOCK_REASON
  14. )
  15. # Import salt libs
  16. import salt.utils.zeromq
  17. from salt.exceptions import SaltSystemExit
  18. class UtilsTestCase(TestCase):
  19. def test_ip_bracket(self):
  20. test_ipv4 = '127.0.0.1'
  21. test_ipv6 = '::1'
  22. self.assertEqual(test_ipv4, salt.utils.zeromq.ip_bracket(test_ipv4))
  23. self.assertEqual('[{0}]'.format(test_ipv6), salt.utils.zeromq.ip_bracket(test_ipv6))
  24. @skipIf(NO_MOCK, NO_MOCK_REASON)
  25. @skipIf(not hasattr(zmq, 'IPC_PATH_MAX_LEN'), "ZMQ does not have max length support.")
  26. def test_check_ipc_length(self):
  27. '''
  28. Ensure we throw an exception if we have a too-long IPC URI
  29. '''
  30. with patch('zmq.IPC_PATH_MAX_LEN', 1):
  31. self.assertRaises(SaltSystemExit, salt.utils.zeromq.check_ipc_path_max_len, '1' * 1024)