unit test for zfs.list

This commit is contained in:
Jorge Schrauwen 2015-12-23 15:20:51 +00:00
parent 3cbc6befbe
commit 11b986e715

View File

@ -25,6 +25,7 @@ ensure_in_syspath('../../')
# Import Salt Execution module to test # Import Salt Execution module to test
from salt.modules import zfs from salt.modules import zfs
from salt.utils.odict import OrderedDict
# Globals # Globals
zfs.__salt__ = {} zfs.__salt__ = {}
@ -182,6 +183,17 @@ class ZfsTestCase(TestCase):
with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}): with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}):
self.assertEqual(zfs.create('myzpool/mydataset/mysubdataset'), res) self.assertEqual(zfs.create('myzpool/mydataset/mysubdataset'), res)
@patch('salt.modules.zfs._check_zfs', MagicMock(return_value='/sbin/zfs'))
def test_list_success(self):
'''
Tests zfs list
'''
res = OrderedDict([('myzpool', {'avail': '79.9M', 'mountpoint': '/myzpool', 'used': '113K', 'refer': '19K'})])
ret = {'pid': 31817, 'retcode': 0, 'stderr': '', 'stdout': 'myzpool\t113K\t79.9M\t19K\t/myzpool'}
mock_cmd = MagicMock(return_value=ret)
with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}):
self.assertEqual(zfs.list_('myzpool'), res)
@patch('salt.modules.zfs._check_zfs', MagicMock(return_value='/sbin/zfs')) @patch('salt.modules.zfs._check_zfs', MagicMock(return_value='/sbin/zfs'))
def test_mount_success(self): def test_mount_success(self):
''' '''