|
8 | 8 | import docker |
9 | 9 |
|
10 | 10 | from fig import Service |
| 11 | +from fig.container import Container |
11 | 12 | from fig.service import ( |
12 | 13 | ConfigError, |
13 | 14 | split_port, |
@@ -44,6 +45,44 @@ def test_config_validation(self): |
44 | 45 | self.assertRaises(ConfigError, lambda: Service(name='foo', port=['8000'])) |
45 | 46 | Service(name='foo', ports=['8000']) |
46 | 47 |
|
| 48 | + def test_get_volumes_from_container(self): |
| 49 | + container_id = 'aabbccddee' |
| 50 | + service = Service( |
| 51 | + 'test', |
| 52 | + volumes_from=[mock.Mock(id=container_id, spec=Container)]) |
| 53 | + |
| 54 | + self.assertEqual(service._get_volumes_from(), [container_id]) |
| 55 | + |
| 56 | + def test_get_volumes_from_intermediate_container(self): |
| 57 | + container_id = 'aabbccddee' |
| 58 | + service = Service('test') |
| 59 | + container = mock.Mock(id=container_id, spec=Container) |
| 60 | + |
| 61 | + self.assertEqual(service._get_volumes_from(container), [container_id]) |
| 62 | + |
| 63 | + def test_get_volumes_from_service_container_exists(self): |
| 64 | + container_ids = ['aabbccddee', '12345'] |
| 65 | + from_service = mock.create_autospec(Service) |
| 66 | + from_service.containers.return_value = [ |
| 67 | + mock.Mock(id=container_id, spec=Container) |
| 68 | + for container_id in container_ids |
| 69 | + ] |
| 70 | + service = Service('test', volumes_from=[from_service]) |
| 71 | + |
| 72 | + self.assertEqual(service._get_volumes_from(), container_ids) |
| 73 | + |
| 74 | + def test_get_volumes_from_service_no_container(self): |
| 75 | + container_id = 'abababab' |
| 76 | + from_service = mock.create_autospec(Service) |
| 77 | + from_service.containers.return_value = [] |
| 78 | + from_service.create_container.return_value = mock.Mock( |
| 79 | + id=container_id, |
| 80 | + spec=Container) |
| 81 | + service = Service('test', volumes_from=[from_service]) |
| 82 | + |
| 83 | + self.assertEqual(service._get_volumes_from(), [container_id]) |
| 84 | + from_service.create_container.assert_called_once_with() |
| 85 | + |
47 | 86 | def test_split_port_with_host_ip(self): |
48 | 87 | internal_port, external_port = split_port("127.0.0.1:1000:2000") |
49 | 88 | self.assertEqual(internal_port, "2000") |
|
0 commit comments