Add rsync make_files filetype raise unit test
The patch add rsync make_files filetype raise unit test Change-Id: Ic93b14218d91d3fe52d5024f86492bca2cc7bc93
This commit is contained in:
parent
cdf5f0e126
commit
ea3d2395d4
|
@ -1052,3 +1052,151 @@ class TestRsyncEngine(unittest.TestCase):
|
|||
mock_set_inode.assert_called_once_with(uname, gname,
|
||||
mtime, fileabspath)
|
||||
self.assertEqual(ret, data_chunk)
|
||||
|
||||
@patch('os.unlink')
|
||||
@patch('freezer.engine.rsync.rsync.'
|
||||
'RsyncEngine.set_inode')
|
||||
@patch('os.symlink')
|
||||
@patch('os.mkfifo')
|
||||
@patch('os.mknod')
|
||||
@patch('os.makedev')
|
||||
@patch('os.makedirs')
|
||||
@patch('freezer.engine.rsync.rsync.'
|
||||
'RsyncEngine.make_reg_file')
|
||||
@patch('os.path.exists')
|
||||
@patch('os.path.isdir')
|
||||
def test_make_files_filetype_l_ok(self, mock_os_path_isdir,
|
||||
mock_os_path_exists,
|
||||
mock_make_reg_file,
|
||||
mock_os_makedirs,
|
||||
mock_os_makedev,
|
||||
mock_os_mknod,
|
||||
mock_os_mkfifo,
|
||||
mock_os_symlink,
|
||||
mock_set_inode,
|
||||
mock_os_unlink):
|
||||
header_len = 128
|
||||
file_path = 'fakefilepath'
|
||||
data_ver = 1
|
||||
file_mode = 2
|
||||
uid = 'fakeuid'
|
||||
gid = 'fakegid'
|
||||
size = 1024
|
||||
mtime = 20181230
|
||||
ctime = 20180302
|
||||
uname = 'fakeuname'
|
||||
gname = 'fakegname'
|
||||
file_type = 'l'
|
||||
link_name = 'fakelink_name'
|
||||
inumber = 'fakeinumber'
|
||||
nlink = 'fakenlink'
|
||||
devminor = 5
|
||||
devmajor = 10
|
||||
rsync_block_size = 'fakersyncblocksize'
|
||||
level_id = '0000'
|
||||
rm = '1112'
|
||||
|
||||
header_list = [header_len, file_path, data_ver, file_mode, uid,
|
||||
gid, size, mtime, ctime, uname, gname, file_type,
|
||||
link_name, inumber, nlink, devminor, devmajor,
|
||||
rsync_block_size, level_id, rm]
|
||||
read_pipe = 'fakeread_pipe'
|
||||
data_chunk = 'fakedatachunk'
|
||||
restore_abs_path = '/home/tecs'
|
||||
flushed = 'True'
|
||||
current_backup_level = 1
|
||||
|
||||
fake_rsync = self.mock_rsync
|
||||
|
||||
mock_os_path_isdir.return_value = mock.MagicMock()
|
||||
mock_os_path_isdir.return_value = True
|
||||
|
||||
mock_os_path_exists.return_value = mock.MagicMock()
|
||||
mock_os_path_exists.return_value = True
|
||||
|
||||
fileabspath = '{0}/{1}'.format(restore_abs_path, file_path)
|
||||
|
||||
ret = fake_rsync.make_files(header_list=header_list,
|
||||
restore_abs_path=restore_abs_path,
|
||||
read_pipe=read_pipe,
|
||||
data_chunk=data_chunk,
|
||||
flushed=flushed,
|
||||
current_backup_level=current_backup_level)
|
||||
|
||||
mock_os_symlink.assert_called_once_with(link_name, fileabspath)
|
||||
self.assertEqual(ret, data_chunk)
|
||||
|
||||
@patch('os.unlink')
|
||||
@patch('freezer.engine.rsync.rsync.'
|
||||
'RsyncEngine.set_inode')
|
||||
@patch('os.symlink')
|
||||
@patch('os.mkfifo')
|
||||
@patch('os.mknod')
|
||||
@patch('os.makedev')
|
||||
@patch('os.makedirs')
|
||||
@patch('freezer.engine.rsync.rsync.'
|
||||
'RsyncEngine.make_reg_file')
|
||||
@patch('os.path.exists')
|
||||
@patch('os.path.isdir')
|
||||
def test_make_files_filetype_d_exception(self, mock_os_path_isdir,
|
||||
mock_os_path_exists,
|
||||
mock_make_reg_file,
|
||||
mock_os_makedirs,
|
||||
mock_os_makedev,
|
||||
mock_os_mknod,
|
||||
mock_os_mkfifo,
|
||||
mock_os_symlink,
|
||||
mock_set_inode,
|
||||
mock_os_unlink):
|
||||
header_len = 128
|
||||
file_path = 'fakefilepath'
|
||||
data_ver = 1
|
||||
file_mode = 2
|
||||
uid = 'fakeuid'
|
||||
gid = 'fakegid'
|
||||
size = 1024
|
||||
mtime = 20181230
|
||||
ctime = 20180302
|
||||
uname = 'fakeuname'
|
||||
gname = 'fakegname'
|
||||
file_type = 'd'
|
||||
link_name = 'fakelink_name'
|
||||
inumber = 'fakeinumber'
|
||||
nlink = 'fakenlink'
|
||||
devminor = 'fakedevminor'
|
||||
devmajor = 'fakedevmajor'
|
||||
rsync_block_size = 'fakersyncblocksize'
|
||||
level_id = '0000'
|
||||
rm = '1112'
|
||||
|
||||
header_list = [header_len, file_path, data_ver, file_mode, uid,
|
||||
gid, size, mtime, ctime, uname, gname, file_type,
|
||||
link_name, inumber, nlink, devminor, devmajor,
|
||||
rsync_block_size, level_id, rm]
|
||||
read_pipe = 'fakeread_pipe'
|
||||
data_chunk = 'fakedatachunk'
|
||||
restore_abs_path = '/home/tecs'
|
||||
flushed = 'True'
|
||||
current_backup_level = 1
|
||||
|
||||
fake_rsync = self.mock_rsync
|
||||
|
||||
mock_os_path_isdir.return_value = mock.MagicMock()
|
||||
mock_os_path_isdir.return_value = False
|
||||
|
||||
mock_os_path_exists.return_value = mock.MagicMock()
|
||||
mock_os_path_exists.return_value = True
|
||||
|
||||
fileabspath = '{0}/{1}'.format(restore_abs_path, file_path)
|
||||
|
||||
mock_os_makedirs.side_effect = OSError
|
||||
|
||||
ret = fake_rsync.make_files(header_list=header_list,
|
||||
restore_abs_path=restore_abs_path,
|
||||
read_pipe=read_pipe,
|
||||
data_chunk=data_chunk,
|
||||
flushed=flushed,
|
||||
current_backup_level=current_backup_level)
|
||||
mock_set_inode.assert_called_once_with(uname, gname,
|
||||
mtime, fileabspath)
|
||||
self.assertEqual(ret, data_chunk)
|
||||
|
|
Loading…
Reference in New Issue