def test_exists_success(self): ''' Tests successful return of exists function ''' ret = {} ret['stdout'] = "NAME USED AVAIL REFER MOUNTPOINT\nmyzpool/mydataset 30K 157G 30K /myzpool/mydataset" ret['stderr'] = '' ret['retcode'] = 0 mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, utils_patch): self.assertTrue(zfs.exists('myzpool/mydataset'))
def test_exists_failure_invalid_name(self): ''' Tests unsuccessful return of exists function if dataset name is invalid ''' ret = {} ret['stdout'] = "" ret['stderr'] = "cannot open 'myzpool/': invalid dataset name" ret['retcode'] = 1 mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, utils_patch): self.assertFalse(zfs.exists('myzpool/'))
def test_exists_failure_not_exists(self): ''' Tests unsuccessful return of exists function if dataset does not exist ''' ret = {} ret['stdout'] = "" ret['stderr'] = "cannot open 'myzpool/mydataset': dataset does not exist" ret['retcode'] = 1 mock_cmd = MagicMock(return_value=ret) with patch.dict(zfs.__salt__, {'cmd.run_all': mock_cmd}), \ patch.dict(zfs.__utils__, self.utils_patch): self.assertFalse(zfs.exists('myzpool/mydataset'))