diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_check_remote_host.py | 47 |
1 files changed, 13 insertions, 34 deletions
diff --git a/tests/test_check_remote_host.py b/tests/test_check_remote_host.py index c5c602d..f7965f3 100644 --- a/tests/test_check_remote_host.py +++ b/tests/test_check_remote_host.py @@ -19,49 +19,28 @@ # import mock +import socket +import plugins from testrunner import PluginsTestCase as TestCaseBase -from plugins.check_remote_host import * -class TestHello(TestCaseBase): - # Method to test the execCmd() method - @mock.patch('check_remote_host.subprocess.Popen') - def testExecCmd(self, mock_popen): - reference = subprocess.Popen('any command', close_fds=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out = "sample output" - err = "" - reference.communicate.return_value = (out, err) - self.assertTrue(reference.communicate, "communicate called") - - # Method to test the getPingStatus() method - @mock.patch('check_remote_host.execCmd') - def testGetPingStatus(self, mock_execCmd): - rc = 0 - out = "sample output" - err = "" - mock_execCmd.return_value = (rc, out, err) - getPingStatus('dummy host') - mock_execCmd.assert_called_with([ - '/usr/lib64/nagios/plugins/check_ping', '-H', 'dummy', 'host', - '-w', '3000.0,80%', '-c', '5000.0,100%']) - self.assertRaises(OSError, execCmd, - ['/usr/lib64/nagios/plugins/check_ping', '-H', - 'dummy', 'host', '-w', '3000.0,80%', '-c', - '5000.0,100%']) - +class TestCheckRemoteHost(TestCaseBase): # Method to test the checkLiveStatus() method - @mock.patch('check_remote_host.socket.socket') + @mock.patch('plugins.check_remote_host.livestatus.socket.socket') def testCheckLiveStatus(self, mock_socket): reference = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.assertTrue(mock_socket, "called") reference.recv.return_value = "0\n" - checkLiveStatus("dummy host", "dummy srvc") - reference.connect.assert_called_with('/var/spool/nagios/cmd/live') + plugins.check_remote_host.checkLiveStatus("dummy host", "dummy srvc") + reference.connect.assert_called_with("${localstatedir}/" + "spool/nagios/cmd/live") reference.send.assert_called_with("GET services\nColumns: state\n" "Filter: description = dummy srvc\n" "Filter: host_address = " - "dummy host\n") - self.assertEquals(0, checkLiveStatus("dummy host", "dummy srvc")) + "dummy host\n" + "Separators: 10 124 44 59") + self.assertEquals(0, + plugins. + check_remote_host. + checkLiveStatus("dummy host", "dummy srvc")) |