| 1 |
from unittest.mock import patch |
| 2 |
|
| 3 |
from unittest.mock import Mock |
| 4 |
import kiwi |
| 5 |
|
| 6 |
from kiwi.defaults import Defaults |
| 7 |
from kiwi.storage.subformat.vdi import DiskFormatVdi |
| 8 |
|
| 9 |
|
| 10 |
class TestDiskFormatVdi: |
| 11 |
def setup(self): |
| 12 |
Defaults.set_platform_name('x86_64') |
| 13 |
xml_data = Mock() |
| 14 |
xml_data.get_name = Mock( |
| 15 |
return_value='some-disk-image' |
| 16 |
) |
| 17 |
self.xml_state = Mock() |
| 18 |
self.xml_state.xml_data = xml_data |
| 19 |
self.xml_state.get_image_version = Mock( |
| 20 |
return_value='1.2.3' |
| 21 |
) |
| 22 |
self.runtime_config = Mock() |
| 23 |
self.runtime_config.get_bundle_compression.return_value = False |
| 24 |
kiwi.storage.subformat.base.RuntimeConfig = Mock( |
| 25 |
return_value=self.runtime_config |
| 26 |
) |
| 27 |
self.disk_format = DiskFormatVdi( |
| 28 |
self.xml_state, 'root_dir', 'target_dir' |
| 29 |
) |
| 30 |
|
| 31 |
def setup_method(self, cls): |
| 32 |
self.setup() |
| 33 |
|
| 34 |
def test_post_init(self): |
| 35 |
self.disk_format.post_init({'option': 'value'}) |
| 36 |
assert self.disk_format.options == ['-o', 'option=value'] |
| 37 |
|
| 38 |
@patch('kiwi.storage.subformat.vdi.Command.run') |
| 39 |
def test_create_image_format(self, mock_command): |
| 40 |
self.disk_format.create_image_format() |
| 41 |
mock_command.assert_called_once_with( |
| 42 |
[ |
| 43 |
'qemu-img', 'convert', '-f', 'raw', |
| 44 |
'target_dir/some-disk-image.x86_64-1.2.3.raw', '-O', 'vdi', |
| 45 |
'target_dir/some-disk-image.x86_64-1.2.3.vdi' |
| 46 |
] |
| 47 |
) |