mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Mock salt.utils.which
cmd.run return values are mocked
This commit is contained in:
parent
e5a96fe00f
commit
627d5ab0c9
@ -141,18 +141,16 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin):
|
||||
self.assertEqual(len(args[0].split()), 6)
|
||||
self.assertEqual(kwargs, {'python_shell': False})
|
||||
|
||||
@skipIf(not salt.utils.which('sync'), 'sync not found')
|
||||
@skipIf(not salt.utils.which('mkfs'), 'mkfs not found')
|
||||
def test_format(self):
|
||||
'''
|
||||
unit tests for disk.format
|
||||
'''
|
||||
device = '/dev/sdX1'
|
||||
mock = MagicMock(return_value=0)
|
||||
with patch.dict(disk.__salt__, {'cmd.retcode': mock}):
|
||||
with patch.dict(disk.__salt__, {'cmd.retcode': mock}),\
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
self.assertEqual(disk.format_(device), True)
|
||||
|
||||
@skipIf(not salt.utils.which('lsblk'), 'lsblk not found')
|
||||
def test_fstype(self):
|
||||
'''
|
||||
unit tests for disk.fstype
|
||||
@ -160,17 +158,18 @@ class DiskTestCase(TestCase, LoaderModuleMockMixin):
|
||||
device = '/dev/sdX1'
|
||||
fs_type = 'ext4'
|
||||
mock = MagicMock(return_value='FSTYPE\n{0}'.format(fs_type))
|
||||
with patch.dict(disk.__grains__, {'kernel': 'Linux'}):
|
||||
with patch.dict(disk.__salt__, {'cmd.run': mock}):
|
||||
with patch.dict(disk.__grains__, {'kernel': 'Linux'}), \
|
||||
patch.dict(disk.__salt__, {'cmd.run': mock}), \
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
self.assertEqual(disk.fstype(device), fs_type)
|
||||
|
||||
@skipIf(not salt.utils.which('resize2fs'), 'resize2fs not found')
|
||||
def test_resize2fs(self):
|
||||
'''
|
||||
unit tests for disk.resize2fs
|
||||
'''
|
||||
device = '/dev/sdX1'
|
||||
mock = MagicMock()
|
||||
with patch.dict(disk.__salt__, {'cmd.run_all': mock}):
|
||||
with patch.dict(disk.__salt__, {'cmd.run_all': mock}), \
|
||||
patch('salt.utils.which', MagicMock(return_value=True)):
|
||||
disk.resize2fs(device)
|
||||
mock.assert_called_once_with('resize2fs {0}'.format(device), python_shell=False)
|
||||
|
Loading…
Reference in New Issue
Block a user