Example #1
0
    def test_build_with_cache(self):
        mock_client = mock.create_autospec(docker.Client)
        service = Service(
            'buildtest',
            client=mock_client,
            build='/path',
            tags=['foo', 'foo:v2'])
        expected = 'abababab'

        with mock.patch('fig.service.stream_output') as mock_stream_output:
            mock_stream_output.return_value = [
                dict(stream='Successfully built %s' % expected)
            ]
            image_id = service.build()
        self.assertEqual(image_id, expected)
        mock_client.build.assert_called_once_with(
            '/path',
            tag=service.full_name,
            stream=True,
            rm=True,
            nocache=False)

        self.assertEqual(mock_client.tag.mock_calls, [
            mock.call(image_id, 'foo', tag=None),
            mock.call(image_id, 'foo', tag='v2'),
        ])
Example #2
0
    def test_create_container_with_build(self):
        self.mock_client.images.return_value = []
        service = Service('foo', client=self.mock_client, build='.')
        service.build = mock.create_autospec(service.build)
        service.create_container(do_build=True)

        self.mock_client.images.assert_called_once_with(name=service.full_name)
        service.build.assert_called_once_with()
Example #3
0
    def test_build_with_cache(self):
        mock_client = mock.create_autospec(docker.Client)
        service = Service('buildtest',
                          client=mock_client,
                          build='/path',
                          tags=['foo', 'foo:v2'])
        expected = 'abababab'

        with mock.patch('fig.service.stream_output') as mock_stream_output:
            mock_stream_output.return_value = [
                dict(stream='Successfully built %s' % expected)
            ]
            image_id = service.build()
        self.assertEqual(image_id, expected)
        mock_client.build.assert_called_once_with('/path',
                                                  tag=service.full_name,
                                                  stream=True,
                                                  rm=True,
                                                  nocache=False)

        self.assertEqual(mock_client.tag.mock_calls, [
            mock.call(image_id, 'foo', tag=None),
            mock.call(image_id, 'foo', tag='v2'),
        ])
Example #4
0
 def test_build_with_build_error(self):
     mock_client = mock.create_autospec(docker.Client)
     service = Service('buildtest', client=mock_client, build='/path')
     with self.assertRaises(BuildError):
         service.build()
Example #5
0
 def test_build_with_build_error(self):
     mock_client = mock.create_autospec(docker.Client)
     service = Service('buildtest', client=mock_client, build='/path')
     with self.assertRaises(BuildError):
         service.build()