kiwi-el8/test/unit/utils_sync_test.py
Marcus Schäfer c429c18289
Added xattr checker for DataSync class
The method target_supports_extended_attributes() checks if the
sync target directory supports extended filesystem attributes.
The method is called on sync_data() and will remove the -X / -A
options if provided. A warning message is issued to the caller
if the rsync option list has changed because of the underlaying
filesystem limitations
2016-05-02 11:16:10 +02:00

46 lines
1.4 KiB
Python

from mock import patch
import mock
from .test_helper import *
from kiwi.exceptions import *
from kiwi.utils.sync import DataSync
class TestDataSync(object):
def setup(self):
self.sync = DataSync('source_dir', 'target_dir')
@patch('kiwi.utils.sync.Command.run')
@patch('kiwi.utils.sync.DataSync.target_supports_extended_attributes')
@patch('kiwi.logger.log.warning')
def test_sync_data(self, mock_warn, mock_xattr_support, mock_command):
mock_xattr_support.return_value = False
self.sync.sync_data(
options=['-a', '-H', '-X', '-A', '--one-file-system'],
exclude=['exclude_me']
)
mock_command.assert_called_once_with(
[
'rsync', '-a', '-H', '--one-file-system',
'--exclude', '/exclude_me', 'source_dir', 'target_dir'
]
)
assert mock_warn.called
@patch('xattr.getxattr')
def test_target_supports_extended_attributes(self, mock_getxattr):
assert self.sync.target_supports_extended_attributes() is True
mock_getxattr.assert_called_once_with(
'target_dir', 'user.mime_type'
)
@patch('xattr.getxattr')
def test_target_supports_extended_attributes(self, mock_getxattr):
mock_getxattr.side_effect = OSError(
"""[Errno 95] Operation not supported: b'/boot/efi"""
)
assert self.sync.target_supports_extended_attributes() is False