mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 02:13:47 +01:00
Add unittest for argsparse
This commit is contained in:
parent
375da5d605
commit
b7c0b0595e
@ -398,7 +398,7 @@ class JsonRuleProcessor:
|
||||
return ("%s" % metrics, warning, critical)
|
||||
|
||||
|
||||
def parseArgs():
|
||||
def parseArgs(args):
|
||||
"""
|
||||
CLI argument definitions and parsing
|
||||
"""
|
||||
@ -497,7 +497,7 @@ def parseArgs():
|
||||
(key[>alias],UnitOfMeasure,WarnRange,
|
||||
CriticalRange).''')
|
||||
|
||||
return parser.parse_args()
|
||||
return parser.parse_args(args)
|
||||
|
||||
|
||||
def debugPrint(debug_flag, message, pretty_flag=False):
|
||||
@ -514,7 +514,8 @@ def debugPrint(debug_flag, message, pretty_flag=False):
|
||||
|
||||
"""Program entry point"""
|
||||
if __name__ == "__main__":
|
||||
args = parseArgs()
|
||||
|
||||
args = parseArgs(sys.argv[1:])
|
||||
nagios = NagiosHelper()
|
||||
context = None
|
||||
|
||||
|
29
test/test_args.py
Normal file
29
test/test_args.py
Normal file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from check_http_json import *
|
||||
|
||||
|
||||
class ArgsTest(unittest.TestCase):
|
||||
"""
|
||||
Tests for argsparse
|
||||
"""
|
||||
|
||||
def test_parser_defaults(self):
|
||||
parser = parseArgs(['-H', 'foobar'])
|
||||
self.assertFalse(parser.debug)
|
||||
self.assertFalse(parser.ssl)
|
||||
self.assertFalse(parser.insecure)
|
||||
|
||||
def test_parser_with_debug(self):
|
||||
parser = parseArgs(['-H', 'foobar', '-d'])
|
||||
self.assertTrue(parser.debug)
|
||||
|
||||
def test_parser_with_port(self):
|
||||
parser = parseArgs(['-H', 'foobar', '-P', '8888'])
|
||||
self.assertEqual(parser.port, '8888')
|
Loading…
Reference in New Issue
Block a user