def test_bookmark_present_fail(self): ''' Test if bookmark is present (using non existing snapshot) ''' ret = { 'name': 'myzpool/filesystem#mybookmark', 'result': False, 'comment': "cannot bookmark snapshot 'zsalt/filesystem@snap': dataset does not exist", 'changes': {} } mock_exists = MagicMock(return_value=False) mock_bookmark = MagicMock(return_value=OrderedDict([ ('bookmarked', False), ('error', "cannot bookmark snapshot 'zsalt/filesystem@snap': dataset does not exist" ), ])) with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \ patch.dict(zfs.__salt__, {'zfs.bookmark': mock_bookmark}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual( ret, zfs.bookmark_present('mybookmark', 'myzpool/filesystem@snap'))
def test_bookmark_present(self): ''' Test if bookmark is present (bookmark already present) ''' ret = { 'name': 'myzpool/filesystem#mybookmark', 'result': True, 'comment': 'bookmark is present', 'changes': {} } mock_exists = MagicMock(return_value=True) with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual( ret, zfs.bookmark_present('mybookmark', 'myzpool/filesystem@snap'))
def test_bookmark_present_new(self): ''' Test if bookmark is present (new) ''' ret = { 'name': 'myzpool/filesystem#mybookmark', 'result': True, 'comment': 'myzpool/filesystem@snap bookmarked as myzpool/filesystem#mybookmark', 'changes': { 'myzpool/filesystem#mybookmark': 'myzpool/filesystem@snap' } } mock_exists = MagicMock(return_value=False) mock_bookmark = MagicMock(return_value=OrderedDict([('bookmarked', True)])) with patch.dict(zfs.__salt__, {'zfs.exists': mock_exists}), \ patch.dict(zfs.__salt__, {'zfs.bookmark': mock_bookmark}), \ patch.dict(zfs.__utils__, utils_patch): self.assertEqual( ret, zfs.bookmark_present('mybookmark', 'myzpool/filesystem@snap'))