mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 02:13:47 +01:00
Extend unittest coverage
This commit is contained in:
parent
1a9e1e9048
commit
2c98e840e8
@ -169,7 +169,7 @@ class JsonHelper:
|
||||
if key.find(self.arrayOpener) != -1:
|
||||
return self.getSubArrayElement(key, data)
|
||||
else:
|
||||
if key in data:
|
||||
if type(data) == dict and key in data:
|
||||
return data[key]
|
||||
else:
|
||||
return (None, 'not_found')
|
||||
|
@ -255,3 +255,20 @@ class UtilTest(unittest.TestCase):
|
||||
# This should not throw a KeyError
|
||||
data = '{}'
|
||||
self.check_data(rules.dash_q(['(0).Node,foobar', '(1).Node,missing']), data, WARNING_CODE)
|
||||
|
||||
def test_subelem(self):
|
||||
|
||||
rules = RulesHelper()
|
||||
data = '{"foo": {"foo": {"foo": "bar"}}}'
|
||||
|
||||
self.check_data(rules.dash_E(['foo.foo.foo.foo.foo']), data, CRITICAL_CODE)
|
||||
|
||||
def test_subarrayelem_missing_elem(self):
|
||||
|
||||
rules = RulesHelper()
|
||||
data = '[{"capacity": {"value": 1000}},{"capacity": {"value": 2200}}]'
|
||||
|
||||
self.check_data(rules.dash_E(['(*).capacity.value']), data, OK_CODE)
|
||||
self.check_data(rules.dash_E(['(*).capacity.value.too_deep']), data, CRITICAL_CODE)
|
||||
# Should not throw keyerror
|
||||
self.check_data(rules.dash_E(['foo']), data, CRITICAL_CODE)
|
||||
|
Loading…
Reference in New Issue
Block a user