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