OLD | NEW |
(Empty) | |
| 1 import socket |
| 2 from unittest import TestCase |
| 3 from juju.lib.port import get_open_port |
| 4 |
| 5 |
| 6 class OpenPortTest(TestCase): |
| 7 |
| 8 def test_get_open_port(self): |
| 9 port = get_open_port() |
| 10 self.assertTrue(isinstance(port, int)) |
| 11 |
| 12 sock = socket.socket( |
| 13 socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
| 14 |
| 15 # would raise an error if we got it wrong. |
| 16 sock.bind(("127.0.0.1", port)) |
| 17 sock.listen(1) |
| 18 sock.close() |
| 19 del sock |
| 20 |
| 21 def test_get_open_port_with_host(self): |
| 22 port = get_open_port("localhost") |
| 23 self.assertTrue(isinstance(port, int)) |
| 24 |
| 25 sock = socket.socket( |
| 26 socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
| 27 |
| 28 # would raise an error if we got it wrong. |
| 29 sock.bind(("127.0.0.1", port)) |
| 30 sock.listen(1) |
| 31 sock.close() |
| 32 del sock |
OLD | NEW |