Exemple #1
0
    def test_net_service_no_containers(self):
        service_name = 'web'
        mock_client = mock.create_autospec(docker.Client)
        mock_client.containers.return_value = []

        service = Service(name=service_name, client=mock_client)
        net = ServiceNet(service)

        self.assertEqual(net.id, service_name)
        self.assertEqual(net.mode, None)
        self.assertEqual(net.service_name, service_name)
Exemple #2
0
    def test_net_service(self):
        container_id = 'bbbb'
        service_name = 'web'
        mock_client = mock.create_autospec(docker.Client)
        mock_client.containers.return_value = [
            {'Id': container_id, 'Name': container_id, 'Image': 'abcd'},
        ]

        service = Service(name=service_name, client=mock_client)
        net = ServiceNet(service)

        self.assertEqual(net.id, service_name)
        self.assertEqual(net.mode, 'container:' + container_id)
        self.assertEqual(net.service_name, service_name)
Exemple #3
0
    def test_config_dict(self):
        self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
        service = Service(
            'foo',
            image='example.com/foo',
            client=self.mock_client,
            net=ServiceNet(Service('other')),
            links=[(Service('one'), 'one')],
            volumes_from=[VolumeFromSpec(Service('two'), 'rw')])

        config_dict = service.config_dict()
        expected = {
            'image_id': 'abcd',
            'options': {'image': 'example.com/foo'},
            'links': [('one', 'one')],
            'net': 'other',
            'volumes_from': [('two', 'rw')],
        }
        self.assertEqual(config_dict, expected)