| 1 |
from unittest.mock import ( |
| 2 |
patch, call |
| 3 |
) |
| 4 |
|
| 5 |
import unittest.mock as mock |
| 6 |
|
| 7 |
from kiwi.filesystem.xfs import FileSystemXfs |
| 8 |
|
| 9 |
|
| 10 |
class TestFileSystemXfs: |
| 11 |
@patch('os.path.exists') |
| 12 |
def setup(self, mock_exists): |
| 13 |
mock_exists.return_value = True |
| 14 |
provider = mock.Mock() |
| 15 |
provider.get_device = mock.Mock( |
| 16 |
return_value='/dev/foo' |
| 17 |
) |
| 18 |
self.xfs = FileSystemXfs(provider, 'root_dir') |
| 19 |
self.xfs.setup_mountpoint = mock.Mock( |
| 20 |
return_value='some-mount-point' |
| 21 |
) |
| 22 |
|
| 23 |
@patch('os.path.exists') |
| 24 |
def setup_method(self, cls, mock_exists): |
| 25 |
self.setup() |
| 26 |
|
| 27 |
@patch('kiwi.filesystem.xfs.Command.run') |
| 28 |
def test_create_on_device(self, mock_command): |
| 29 |
with patch.dict('os.environ', {'SOURCE_DATE_EPOCH': '0'}): |
| 30 |
self.xfs.create_on_device('label', 100, uuid='uuid') |
| 31 |
call = mock_command.call_args_list[0] |
| 32 |
assert mock_command.call_args_list[0] == call( |
| 33 |
[ |
| 34 |
'mkfs.xfs', '-f', '-L', 'label', |
| 35 |
'-m', 'uuid=uuid', '-d', 'size=100k', '/dev/foo' |
| 36 |
] |
| 37 |
) |
| 38 |
mock_command.reset_mock() |
| 39 |
self.xfs.create_on_device('label', 100) |
| 40 |
assert mock_command.call_args_list[0] == call( |
| 41 |
[ |
| 42 |
'mkfs.xfs', '-f', |
| 43 |
'-L', 'label', |
| 44 |
'-m', 'uuid=2453562e-7073-2098-d091-fd7a04dc5434', |
| 45 |
'-d', 'size=100k', |
| 46 |
'/dev/foo' |
| 47 |
] |
| 48 |
) |
| 49 |
|
| 50 |
@patch('kiwi.filesystem.xfs.Command.run') |
| 51 |
def test_set_uuid(self, mock_command): |
| 52 |
self.xfs.set_uuid() |
| 53 |
assert mock_command.call_args_list == [ |
| 54 |
call(['xfs_repair', '-L', '/dev/foo']), |
| 55 |
call(['xfs_admin', '-U', 'generate', '/dev/foo']) |
| 56 |
] |