Tests: added regex check.
This commit is contained in:
@@ -19,6 +19,7 @@ from unit.check.go import check_go
|
|||||||
from unit.check.isolation import check_isolation
|
from unit.check.isolation import check_isolation
|
||||||
from unit.check.node import check_node
|
from unit.check.node import check_node
|
||||||
from unit.check.tls import check_openssl
|
from unit.check.tls import check_openssl
|
||||||
|
from unit.check.regex import check_regex
|
||||||
from unit.http import TestHTTP
|
from unit.http import TestHTTP
|
||||||
from unit.option import option
|
from unit.option import option
|
||||||
from unit.utils import public_dir
|
from unit.utils import public_dir
|
||||||
@@ -176,6 +177,7 @@ def pytest_sessionstart(session):
|
|||||||
option.current_dir, unit['temp_dir'], option.test_dir
|
option.current_dir, unit['temp_dir'], option.test_dir
|
||||||
)
|
)
|
||||||
option.available['modules']['node'] = check_node(option.current_dir)
|
option.available['modules']['node'] = check_node(option.current_dir)
|
||||||
|
option.available['modules']['regex'] = check_regex(unit['unitd'])
|
||||||
|
|
||||||
# remove None values
|
# remove None values
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,9 @@ class TestRouting(TestApplicationProto):
|
|||||||
assert self.get(url='/ABc')['status'] == 404
|
assert self.get(url='/ABc')['status'] == 404
|
||||||
|
|
||||||
def test_routes_empty_regex(self):
|
def test_routes_empty_regex(self):
|
||||||
|
if not option.available['modules']['regex']:
|
||||||
|
pytest.skip('requires regex')
|
||||||
|
|
||||||
self.route_match({"uri":"~"})
|
self.route_match({"uri":"~"})
|
||||||
assert self.get(url='/')['status'] == 200, 'empty regexp'
|
assert self.get(url='/')['status'] == 200, 'empty regexp'
|
||||||
assert self.get(url='/anything')['status'] == 200, '/anything'
|
assert self.get(url='/anything')['status'] == 200, '/anything'
|
||||||
@@ -238,6 +241,9 @@ class TestRouting(TestApplicationProto):
|
|||||||
assert self.get(url='/nothing')['status'] == 404, '/nothing'
|
assert self.get(url='/nothing')['status'] == 404, '/nothing'
|
||||||
|
|
||||||
def test_routes_bad_regex(self):
|
def test_routes_bad_regex(self):
|
||||||
|
if not option.available['modules']['regex']:
|
||||||
|
pytest.skip('requires regex')
|
||||||
|
|
||||||
assert 'error' in self.route(
|
assert 'error' in self.route(
|
||||||
{"match": {"uri": "~/bl[ah"}, "action": {"return": 200}}
|
{"match": {"uri": "~/bl[ah"}, "action": {"return": 200}}
|
||||||
), 'bad regex'
|
), 'bad regex'
|
||||||
@@ -255,6 +261,9 @@ class TestRouting(TestApplicationProto):
|
|||||||
assert self.get(url='/nothing_z')['status'] == 500, '/nothing_z'
|
assert self.get(url='/nothing_z')['status'] == 500, '/nothing_z'
|
||||||
|
|
||||||
def test_routes_match_regex_case_sensitive(self):
|
def test_routes_match_regex_case_sensitive(self):
|
||||||
|
if not option.available['modules']['regex']:
|
||||||
|
pytest.skip('requires regex')
|
||||||
|
|
||||||
self.route_match({"uri": "~/bl[ah]"})
|
self.route_match({"uri": "~/bl[ah]"})
|
||||||
|
|
||||||
assert self.get(url='/rlah')['status'] == 404, '/rlah'
|
assert self.get(url='/rlah')['status'] == 404, '/rlah'
|
||||||
@@ -263,6 +272,9 @@ class TestRouting(TestApplicationProto):
|
|||||||
assert self.get(url='/BLAH')['status'] == 404, '/BLAH'
|
assert self.get(url='/BLAH')['status'] == 404, '/BLAH'
|
||||||
|
|
||||||
def test_routes_match_regex_negative_case_sensitive(self):
|
def test_routes_match_regex_negative_case_sensitive(self):
|
||||||
|
if not option.available['modules']['regex']:
|
||||||
|
pytest.skip('requires regex')
|
||||||
|
|
||||||
self.route_match({"uri": "!~/bl[ah]"})
|
self.route_match({"uri": "!~/bl[ah]"})
|
||||||
|
|
||||||
assert self.get(url='/rlah')['status'] == 200, '/rlah'
|
assert self.get(url='/rlah')['status'] == 200, '/rlah'
|
||||||
|
|||||||
13
test/unit/check/regex.py
Normal file
13
test/unit/check/regex.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def check_regex(unitd):
|
||||||
|
output = subprocess.check_output(
|
||||||
|
[unitd, '--version'], stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
|
||||||
|
if re.search('--no-regex', output.decode()):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
Reference in New Issue
Block a user