Debian Codegraph @

test/unit/oci_tools/base_test.py

raw
1 from pytest import raises
2 from unittest.mock import Mock, patch
3
4 from kiwi.oci_tools.base import OCIBase
5
6
7 class TestOCIBase:
8 def setup(self):
9 self.oci = OCIBase()
10
11 def setup_method(self, cls):
12 self.setup()
13
14 def test_init_container(self):
15 with raises(NotImplementedError):
16 self.oci.init_container()
17
18 def test_import_container_image(self):
19 with raises(NotImplementedError):
20 self.oci.import_container_image('oci-archive:image.xz')
21
22 def test_export_container_image(self):
23 with raises(NotImplementedError):
24 self.oci.export_container_image(
25 'image.xz', 'docker-archive', 'myimage:tag'
26 )
27
28 def test_unpack(self):
29 with raises(NotImplementedError):
30 self.oci.unpack()
31
32 def test_sync_rootfs(self):
33 with raises(NotImplementedError):
34 self.oci.sync_rootfs('root_dir')
35
36 def test_import_rootfs(self):
37 with raises(NotImplementedError):
38 self.oci.import_rootfs('root_dir')
39
40 def test_repack(self):
41 with raises(NotImplementedError):
42 self.oci.repack({})
43
44 def test_set_config(self):
45 with raises(NotImplementedError):
46 self.oci.set_config({})
47
48 def test_post_process(self):
49 with raises(NotImplementedError):
50 self.oci.post_process()
51
52 @patch('kiwi.oci_tools.base.Path.which')
53 @patch('kiwi.oci_tools.base.CommandCapabilities.check_version')
54 def test_skopeo_provides_tmpdir_option(
55 self, mock_Path_which, mock_CommandCapabilities_check_version
56 ):
57 mock_Path_which.return_value = 'skopeo'
58 mock_CommandCapabilities_check_version.return_value = (0, 2, 0)
59 assert self.oci._skopeo_provides_tmpdir_option() is True
60 mock_Path_which.return_value = None
61 assert self.oci._skopeo_provides_tmpdir_option() is False
62
63 @patch('kiwi.oci_tools.base.datetime')
64 def test_creation_date(self, mock_datetime):
65 strftime = Mock()
66 strftime.strftime = Mock(return_value='current_date')
67 mock_datetime.utcnow = Mock(
68 return_value=strftime
69 )
70
71 with patch.dict('os.environ', {'SOURCE_DATE_EPOCH': ''}):
72 oci = OCIBase()
73 assert oci.creation_date == 'current_date'
74
75 def test_creation_date_from_source_date_epoch(self):
76 with patch.dict('os.environ', {'SOURCE_DATE_EPOCH': '946729830'}):
77 oci = OCIBase()
78 assert oci.creation_date == '2000-01-01T12:30:30+00:00'