mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_logadm to pytest
This commit is contained in:
parent
21463a2f46
commit
ee1e9fdfeb
2 changed files with 64 additions and 66 deletions
64
tests/pytests/unit/modules/test_logadm.py
Normal file
64
tests/pytests/unit/modules/test_logadm.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
"""
|
||||
:codeauthor: Rupesh Tare <rupesht@saltstack.com>
|
||||
|
||||
Test cases for salt.modules.logadm
|
||||
"""
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.logadm as logadm
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
return {logadm: {}}
|
||||
|
||||
|
||||
def test_show_conf():
|
||||
"""
|
||||
Test for Show parsed configuration
|
||||
"""
|
||||
with patch.object(logadm, "_parse_conf", return_value=True):
|
||||
assert logadm.show_conf("conf_file")
|
||||
|
||||
|
||||
def test_rotate():
|
||||
"""
|
||||
Test for Set up pattern for logging.
|
||||
"""
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 1, "stderr": "stderr"})},
|
||||
):
|
||||
assert logadm.rotate("name") == {
|
||||
"Output": "stderr",
|
||||
"Error": "Failed in adding log",
|
||||
}
|
||||
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 0, "stderr": "stderr"})},
|
||||
):
|
||||
assert logadm.rotate("name") == {"Result": "Success"}
|
||||
|
||||
|
||||
def test_remove():
|
||||
"""
|
||||
Test for Remove log pattern from logadm
|
||||
"""
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 1, "stderr": "stderr"})},
|
||||
):
|
||||
assert logadm.remove("name") == {
|
||||
"Output": "stderr",
|
||||
"Error": "Failure in removing log. Possibly already removed?",
|
||||
}
|
||||
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 0, "stderr": "stderr"})},
|
||||
):
|
||||
assert logadm.remove("name") == {"Result": "Success"}
|
|
@ -1,66 +0,0 @@
|
|||
"""
|
||||
:codeauthor: Rupesh Tare <rupesht@saltstack.com>
|
||||
"""
|
||||
|
||||
|
||||
import salt.modules.logadm as logadm
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class LogadmTestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
Test cases for salt.modules.logadm
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {logadm: {}}
|
||||
|
||||
def test_show_conf(self):
|
||||
"""
|
||||
Test for Show parsed configuration
|
||||
"""
|
||||
with patch.object(logadm, "_parse_conf", return_value=True):
|
||||
self.assertTrue(logadm.show_conf("conf_file"))
|
||||
|
||||
def test_rotate(self):
|
||||
"""
|
||||
Test for Set up pattern for logging.
|
||||
"""
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 1, "stderr": "stderr"})},
|
||||
):
|
||||
self.assertEqual(
|
||||
logadm.rotate("name"),
|
||||
{"Output": "stderr", "Error": "Failed in adding log"},
|
||||
)
|
||||
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 0, "stderr": "stderr"})},
|
||||
):
|
||||
self.assertEqual(logadm.rotate("name"), {"Result": "Success"})
|
||||
|
||||
def test_remove(self):
|
||||
"""
|
||||
Test for Remove log pattern from logadm
|
||||
"""
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 1, "stderr": "stderr"})},
|
||||
):
|
||||
self.assertEqual(
|
||||
logadm.remove("name"),
|
||||
{
|
||||
"Output": "stderr",
|
||||
"Error": "Failure in removing log. Possibly already removed?",
|
||||
},
|
||||
)
|
||||
|
||||
with patch.dict(
|
||||
logadm.__salt__,
|
||||
{"cmd.run_all": MagicMock(return_value={"retcode": 0, "stderr": "stderr"})},
|
||||
):
|
||||
self.assertEqual(logadm.remove("name"), {"Result": "Success"})
|
Loading…
Add table
Reference in a new issue