added unit tests for zfs.holds

This commit is contained in:
Jorge Schrauwen 2015-12-23 21:16:45 +00:00
parent 9276556155
commit 596c991c0b

View File

@ -369,6 +369,28 @@ class ZfsTestCase(TestCase):
with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}):
self.assertEqual(zfs.bookmark('myzpool/mydataset@yesterday', 'myzpool/mydataset#important'), res)
@patch('salt.modules.zfs._check_zfs', MagicMock(return_value='/sbin/zfs'))
def test_holds_success(self):
'''
Tests zfs holds success
'''
res = {'myzpool/mydataset@baseline': {'important ': 'Wed Dec 23 21:06 2015', 'release-1.0': 'Wed Dec 23 21:08 2015'}}
ret = {'pid': 40216, 'retcode': 0, 'stderr': '', 'stdout': 'myzpool/mydataset@baseline\timportant \tWed Dec 23 21:06 2015\nmyzpool/mydataset@baseline\trelease-1.0\tWed Dec 23 21:08 2015'}
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}):
self.assertEqual(zfs.holds('myzpool/mydataset@baseline'), res)
@patch('salt.modules.zfs._check_zfs', MagicMock(return_value='/sbin/zfs'))
def test_holds_failure(self):
'''
Tests zfs holds failure
'''
res = {'myzpool/mydataset@baseline': "cannot open 'myzpool/mydataset@baseline': dataset does not exist"}
ret = {'pid': 40993, 'retcode': 1, 'stderr': "cannot open 'myzpool/mydataset@baseline': dataset does not exist", 'stdout': 'no datasets available'}
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}):
self.assertEqual(zfs.holds('myzpool/mydataset@baseline'), res)
if __name__ == '__main__':
from integration import run_tests
run_tests(ZfsTestCase, needs_daemon=False)