Module: check_mk
Branch: master
Commit: 5ad191209f8d47510c0d13ed6c1560e293e344fa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5ad191209f8d47…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri Mar 22 11:41:13 2019 +0100
check_http: tests + minor refactor
* make tests consider order, as it might become relevant
* add some test cases
* simplify "-I" logic in check
Change-Id: I894d6633a9775dedcd870c2041772020330c54bf
---
checks/check_http | 6 +--
tests/unit/checks/test_check_http.py | 80 ++++++++++++++++++++++++------------
2 files changed, 56 insertions(+), 30 deletions(-)
diff --git a/checks/check_http b/checks/check_http
index b493b0d..e1c265d 100644
--- a/checks/check_http
+++ b/checks/check_http
@@ -90,10 +90,10 @@ def _url_args(address_family, address, settings):
args = []
- if (not omit_ip) and ("proxy" not in settings):
- args += ["-I", address]
- elif "proxy" in settings:
+ if "proxy" in settings:
args += ["-I", settings["proxy"]]
+ elif not omit_ip:
+ args += ["-I", address]
if vhost:
args += ["-H", vhost]
diff --git a/tests/unit/checks/test_check_http.py b/tests/unit/checks/test_check_http.py
index f4c638d..eae8884 100644
--- a/tests/unit/checks/test_check_http.py
+++ b/tests/unit/checks/test_check_http.py
@@ -3,9 +3,8 @@ import pytest
pytestmark = pytest.mark.checks
-(a)pytest.mark.parametrize(
- 'params,expected_args',
- [(
+(a)pytest.mark.parametrize('params,expected_args'rgs', [
+ (
(None, {
'onredirect': 'follow',
'port': 80,
@@ -15,32 +14,59 @@ pytestmark = pytest.mark.checks
}),
['-H', 'www.test123.de', '-p', 80, '-u',
'/images', '--onredirect=follow', '-L'],
),
- (
- (None, {
- 'extended_perfdata': True,
- 'method': 'CONNECT',
- 'port': 3128,
- 'proxy': '163.172.86.64',
- 'ssl': 'auto',
- 'uri': '/images',
- 'virthost': ('www.test123.de', True)
- }),
- [
- '-I', '163.172.86.64', '-H',
'www.test123.de', '-p', 3128, '-u', '/images',
'--ssl',
- '--extended-perfdata', '-j', 'CONNECT'
- ],
- ),
- (
- (None, {
- 'cert_days': (10, 20),
- 'cert_host': 'www.test123.com'
- }),
- ['-I', 'www.test123.com', '-C', '10,20'],
- )])
+ (
+ (None, {
+ 'extended_perfdata': True,
+ 'method': 'CONNECT',
+ 'port': 3128,
+ 'proxy': '163.172.86.64',
+ 'ssl': 'auto',
+ 'uri': '/images',
+ 'virthost': ('www.test123.de', True)
+ }),
+ [
+ '-I', '163.172.86.64', '-H',
'www.test123.de', '-p', 3128, '-u', '/images',
'--ssl',
+ '--extended-perfdata', '-j', 'CONNECT'
+ ],
+ ),
+ (
+ (None, {
+ 'cert_days': (10, 20),
+ 'cert_host': 'www.test123.com'
+ }),
+ ['-I', 'www.test123.com', '-C', '10,20'],
+ ),
+ (
+ (None, {
+ 'virthost': (None, True),
+ 'proxy': "foo.bar",
+ }),
+ ['-I', 'foo.bar'],
+ ),
+ (
+ (None, {
+ 'virthost': (None, False),
+ 'proxy': "foo.bar",
+ }),
+ ['-I', 'foo.bar'],
+ ),
+ (
+ (None, {
+ 'virthost': (None, True),
+ }),
+ [],
+ ),
+ (
+ (None, {
+ 'virthost': (None, False),
+ }),
+ ['-I', '$_HOSTADDRESS_4$'],
+ ),
+])
def test_check_http_argument_parsing(check_manager, params, expected_args):
- """Tests if all required arguments are present. The tests do not check
the order of arguments."""
+ """Tests if all required arguments are present."""
active_check = check_manager.get_active_check('check_http')
- assert sorted(active_check.run_argument_function(params)) == sorted(expected_args)
+ assert active_check.run_argument_function(params) == expected_args
@pytest.mark.parametrize('params,expected_description', [