mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #19340 from nmadhok/zpool-unit-test
Adding unit tests for salt.modules.zpool
This commit is contained in:
commit
f01ce36e89
49
tests/unit/modules/zpool_test.py
Normal file
49
tests/unit/modules/zpool_test.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: Nitin Madhok <nmadhok@clemson.edu>`
|
||||
|
||||
tests.unit.modules.zpool_test
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
# Import Mock libraries
|
||||
from salttesting.mock import (
|
||||
MagicMock,
|
||||
patch,
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
)
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt Execution module to test
|
||||
from salt.modules import zpool
|
||||
|
||||
# Globals
|
||||
zpool.__salt__ = {}
|
||||
|
||||
|
||||
# Skip this test case if we don't have access to mock!
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class ZpoolTestCase(TestCase):
|
||||
'''
|
||||
This class contains a set of functions that test salt.modules.zpool module
|
||||
'''
|
||||
|
||||
@patch('salt.modules.zpool._check_zpool', MagicMock(return_value='/sbin/zpool'))
|
||||
def test_exists_success(self):
|
||||
'''
|
||||
Tests successful return of exists function
|
||||
'''
|
||||
ret = "NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT\nmyzpool 149G 128K 149G 0% 1.00x ONLINE -"
|
||||
mock_cmd = MagicMock(return_value=ret)
|
||||
with patch.dict(zpool.__salt__, {'cmd.run': mock_cmd}):
|
||||
self.assertTrue(zpool.exists('myzpool'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(ZpoolTestCase, needs_daemon=False)
|
Loading…
Reference in New Issue
Block a user