예제 #1
0
 def test_port_ranges_with_bind_host(self):
     port_mappings = PortMappings(bind_host="0.0.0.0")
     port_mappings.add(5000)
     port_mappings.add(5001)
     port_mappings.add(5003)
     result = port_mappings.to_str()
     self.assertEqual("-p 0.0.0.0:5000-5001:5000-5001 -p 0.0.0.0:5003:5003", result)
예제 #2
0
 def test_overlapping_port_ranges(self):
     port_mappings = PortMappings()
     port_mappings.add(4590)
     port_mappings.add(4591)
     port_mappings.add(4593)
     port_mappings.add(4592)
     port_mappings.add(4593)
     result = port_mappings.to_str()
     # assert that ranges are non-overlapping, i.e., no duplicate ports
     self.assertEqual('-p 4590-4592:4590-4592 -p 4593:4593', result)
예제 #3
0
    def test_port_mappings(self):
        map = PortMappings()
        map.add(123)
        self.assertEqual('-p 123:123', map.to_str())
        map.add(124)
        self.assertEqual('-p 123-124:123-124', map.to_str())
        map.add(234)
        self.assertEqual('-p 123-124:123-124 -p 234:234', map.to_str())
        map.add(345, 346)
        self.assertEqual('-p 123-124:123-124 -p 234:234 -p 345:346',
                         map.to_str())
        map.add([456, 458])
        self.assertEqual(
            '-p 123-124:123-124 -p 234:234 -p 345:346 -p 456-458:456-458',
            map.to_str())

        map = PortMappings()
        map.add([123, 124])
        self.assertEqual('-p 123-124:123-124', map.to_str())
        map.add([234, 237], [345, 348])
        self.assertEqual('-p 123-124:123-124 -p 234-237:345-348', map.to_str())
예제 #4
0
 def test_create_with_port_mapping(self, docker_client: DockerClient, create_container):
     ports = PortMappings()
     ports.add(45122, 22)
     ports.add(45180, 80)
     create_container("alpine", ports=ports)