| 1 |
from unittest.mock import ( |
| 2 |
patch, Mock |
| 3 |
) |
| 4 |
from pytest import raises |
| 5 |
|
| 6 |
from kiwi.builder import ImageBuilder |
| 7 |
|
| 8 |
from kiwi.exceptions import KiwiRequestedTypeError |
| 9 |
|
| 10 |
|
| 11 |
class TestImageBuilder: |
| 12 |
@patch('kiwi.builder.filesystem.FileSystemBuilder') |
| 13 |
def test_filesystem_builder(self, mock_builder): |
| 14 |
xml_state = Mock() |
| 15 |
xml_state.get_build_type_name = Mock( |
| 16 |
return_value='ext4' |
| 17 |
) |
| 18 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 19 |
mock_builder.assert_called_once_with( |
| 20 |
xml_state, 'target_dir', 'root_dir', None |
| 21 |
) |
| 22 |
|
| 23 |
@patch('kiwi.builder.disk.DiskBuilder') |
| 24 |
def test_disk_builder(self, mock_builder): |
| 25 |
xml_state = Mock() |
| 26 |
xml_state.get_build_type_name = Mock( |
| 27 |
return_value='oem' |
| 28 |
) |
| 29 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 30 |
mock_builder.assert_called_once_with( |
| 31 |
xml_state, 'target_dir', 'root_dir', None |
| 32 |
) |
| 33 |
|
| 34 |
@patch('kiwi.builder.live.LiveImageBuilder') |
| 35 |
def test_live_builder(self, mock_builder): |
| 36 |
xml_state = Mock() |
| 37 |
xml_state.get_build_type_name = Mock( |
| 38 |
return_value='iso' |
| 39 |
) |
| 40 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 41 |
mock_builder.assert_called_once_with( |
| 42 |
xml_state, 'target_dir', 'root_dir', None |
| 43 |
) |
| 44 |
|
| 45 |
@patch('kiwi.builder.kis.KisBuilder') |
| 46 |
def test_kis_builder(self, mock_builder): |
| 47 |
xml_state = Mock() |
| 48 |
xml_state.get_build_type_name = Mock( |
| 49 |
return_value='kis' |
| 50 |
) |
| 51 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 52 |
mock_builder.assert_called_once_with( |
| 53 |
xml_state, 'target_dir', 'root_dir', None |
| 54 |
) |
| 55 |
mock_builder.reset_mock() |
| 56 |
xml_state.get_build_type_name = Mock( |
| 57 |
return_value='pxe' |
| 58 |
) |
| 59 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 60 |
mock_builder.assert_called_once_with( |
| 61 |
xml_state, 'target_dir', 'root_dir', None |
| 62 |
) |
| 63 |
|
| 64 |
@patch('kiwi.builder.enclave.EnclaveBuilder') |
| 65 |
def test_enclave_builder(self, mock_builder): |
| 66 |
xml_state = Mock() |
| 67 |
xml_state.get_build_type_name = Mock( |
| 68 |
return_value='enclave' |
| 69 |
) |
| 70 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 71 |
mock_builder.assert_called_once_with( |
| 72 |
xml_state, 'target_dir', 'root_dir', None |
| 73 |
) |
| 74 |
|
| 75 |
@patch('kiwi.builder.archive.ArchiveBuilder') |
| 76 |
def test_archive_builder(self, mock_builder): |
| 77 |
xml_state = Mock() |
| 78 |
xml_state.get_build_type_name = Mock( |
| 79 |
return_value='tbz' |
| 80 |
) |
| 81 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 82 |
mock_builder.assert_called_once_with( |
| 83 |
xml_state, 'target_dir', 'root_dir', None |
| 84 |
) |
| 85 |
|
| 86 |
@patch('kiwi.builder.container.ContainerBuilder') |
| 87 |
def test_container_builder(self, mock_builder): |
| 88 |
xml_state = Mock() |
| 89 |
xml_state.get_build_type_name = Mock( |
| 90 |
return_value='docker' |
| 91 |
) |
| 92 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |
| 93 |
mock_builder.assert_called_once_with( |
| 94 |
xml_state, 'target_dir', 'root_dir', None |
| 95 |
) |
| 96 |
|
| 97 |
def test_unsupported_build_type(self): |
| 98 |
xml_state = Mock() |
| 99 |
xml_state.get_build_type_name = Mock( |
| 100 |
return_value='bogus' |
| 101 |
) |
| 102 |
with raises(KiwiRequestedTypeError): |
| 103 |
ImageBuilder.new(xml_state, 'target_dir', 'root_dir') |