diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/applications/lang/go.py | 5 | ||||
-rw-r--r-- | test/unit/applications/proto.py | 14 | ||||
-rw-r--r-- | test/unit/check/unix_abstract.py | 25 | ||||
-rw-r--r-- | test/unit/http.py | 6 | ||||
-rw-r--r-- | test/unit/status.py | 45 |
5 files changed, 84 insertions, 11 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py index 04af26e1..3db955f3 100644 --- a/test/unit/applications/lang/go.py +++ b/test/unit/applications/lang/go.py @@ -9,6 +9,11 @@ from unit.option import option class TestApplicationGo(TestApplicationProto): @staticmethod def prepare_env(script, name='app', static=False): + try: + subprocess.check_output(['which', 'go']) + except subprocess.CalledProcessError: + return None + temp_dir = option.temp_dir + '/go/' if not os.path.exists(temp_dir): diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py index cd8672ba..f04ee408 100644 --- a/test/unit/applications/proto.py +++ b/test/unit/applications/proto.py @@ -13,21 +13,21 @@ class TestApplicationProto(TestControl): def sec_epoch(self): return time.mktime(time.gmtime()) - def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'): + def date_to_sec_epoch(self, date, template='%a, %d %b %Y %X %Z'): return time.mktime(time.strptime(date, template)) - def findall(self, pattern, name='unit.log'): + def findall(self, pattern, name='unit.log', flags=re.M): with Log.open(name) as f: - return re.findall(pattern, f.read()) + return re.findall(pattern, f.read(), flags) - def search_in_log(self, pattern, name='unit.log'): + def search_in_log(self, pattern, name='unit.log', flags=re.M): with Log.open(name) as f: - return re.search(pattern, f.read()) + return re.search(pattern, f.read(), flags) - def wait_for_record(self, pattern, name='unit.log', wait=150): + def wait_for_record(self, pattern, name='unit.log', wait=150, flags=re.M): with Log.open(name) as f: for i in range(wait): - found = re.search(pattern, f.read()) + found = re.search(pattern, f.read(), flags) if found is not None: break diff --git a/test/unit/check/unix_abstract.py b/test/unit/check/unix_abstract.py new file mode 100644 index 00000000..5d1f629e --- /dev/null +++ b/test/unit/check/unix_abstract.py @@ -0,0 +1,25 @@ +import json + +from unit.http import TestHTTP +from unit.option import option + +http = TestHTTP() + + +def check_unix_abstract(): + available = option.available + + resp = http.put( + url='/config', + sock_type='unix', + addr=option.temp_dir + '/control.unit.sock', + body=json.dumps( + { + "listeners": {"unix:@sock": {"pass": "routes"}}, + "routes": [], + } + ), + ) + + if 'success' in resp['body']: + available['features']['unix_abstract'] = True diff --git a/test/unit/http.py b/test/unit/http.py index b4a1a17b..b29667c9 100644 --- a/test/unit/http.py +++ b/test/unit/http.py @@ -51,7 +51,7 @@ class TestHTTP: connect_args = addr if sock_type == 'unix' else (addr, port) try: sock.connect(connect_args) - except ConnectionRefusedError: + except (ConnectionRefusedError, FileNotFoundError): sock.close() pytest.fail('Client can\'t connect to the server.') @@ -209,9 +209,7 @@ class TestHTTP: return {} headers_text, body = m.group(1), m.group(2) - - p = re.compile('(.*?)\x0d\x0a?', re.M | re.S) - headers_lines = p.findall(headers_text) + headers_lines = re.findall('(.*?)\x0d\x0a?', headers_text, re.M | re.S) status = re.search( r'^HTTP\/\d\.\d\s(\d+)|$', headers_lines.pop(0) diff --git a/test/unit/status.py b/test/unit/status.py new file mode 100644 index 00000000..17416f17 --- /dev/null +++ b/test/unit/status.py @@ -0,0 +1,45 @@ +from unit.control import TestControl + + +class Status: + _status = None + control = TestControl() + + def _check_zeros(): + assert Status.control.conf_get('/status') == { + 'connections': { + 'accepted': 0, + 'active': 0, + 'idle': 0, + 'closed': 0, + }, + 'requests': {'total': 0}, + 'applications': {}, + } + + def init(status=None): + Status._status = ( + status if status is not None else Status.control.conf_get('/status') + ) + + def diff(): + def find_diffs(d1, d2): + if isinstance(d1, dict) and isinstance(d2, dict): + return { + k: find_diffs(d1.get(k, 0), d2.get(k, 0)) + for k in d1 + if k in d2 + } + else: + return d1 - d2 + + return find_diffs(Status.control.conf_get('/status'), Status._status) + + def get(path='/'): + path = path.split('/')[1:] + diff = Status.diff() + + for p in path: + diff = diff[p] + + return diff |