| 1 |
from pytest import raises |
| 2 |
from unittest.mock import ( |
| 3 |
patch, Mock |
| 4 |
) |
| 5 |
|
| 6 |
from kiwi.oci_tools import OCI |
| 7 |
|
| 8 |
from kiwi.exceptions import ( |
| 9 |
KiwiOCIArchiveToolError |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
class TestOCI: |
| 14 |
def setup(self): |
| 15 |
self.runtime_config = Mock() |
| 16 |
self.runtime_config.get_oci_archive_tool = Mock() |
| 17 |
|
| 18 |
def setup_method(self, cls): |
| 19 |
self.setup() |
| 20 |
|
| 21 |
@patch('kiwi.oci_tools.umoci.OCIUmoci') |
| 22 |
@patch('kiwi.oci_tools.RuntimeConfig') |
| 23 |
def test_oci_tool_umoci( |
| 24 |
self, mock_RuntimeConfig, mock_OCIUmoci |
| 25 |
): |
| 26 |
self.runtime_config.get_oci_archive_tool.return_value = 'umoci' |
| 27 |
mock_RuntimeConfig.return_value = self.runtime_config |
| 28 |
OCI.new() |
| 29 |
mock_OCIUmoci.assert_called_once_with() |
| 30 |
|
| 31 |
@patch('kiwi.oci_tools.buildah.OCIBuildah') |
| 32 |
@patch('kiwi.oci_tools.RuntimeConfig') |
| 33 |
def test_oci_tool_buildah( |
| 34 |
self, mock_RuntimeConfig, mock_OCIBuildah |
| 35 |
): |
| 36 |
self.runtime_config.get_oci_archive_tool.return_value = 'buildah' |
| 37 |
mock_RuntimeConfig.return_value = self.runtime_config |
| 38 |
OCI.new() |
| 39 |
mock_OCIBuildah.assert_called_once_with() |
| 40 |
|
| 41 |
@patch('kiwi.oci_tools.RuntimeConfig') |
| 42 |
def test_oci_tool_not_supported(self, mock_RuntimeConfig): |
| 43 |
self.runtime_config.get_oci_archive_tool.return_value = 'foo' |
| 44 |
mock_RuntimeConfig.return_value = self.runtime_config |
| 45 |
with raises(KiwiOCIArchiveToolError): |
| 46 |
OCI.new() |