summaryrefslogtreecommitdiffhomepage
path: root/test/unit/http.py
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2020-03-02 13:10:38 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2020-03-02 13:10:38 +0000
commitf68947bc60c930d460e1bd71bb5f486579009578 (patch)
tree40643ed3599e8dd0ffd19ce9954a4f4142b12e23 /test/unit/http.py
parent5d67879a5051f7e3d3b4dd96da4f43e7822f7da4 (diff)
downloadunit-f68947bc60c930d460e1bd71bb5f486579009578.tar.gz
unit-f68947bc60c930d460e1bd71bb5f486579009578.tar.bz2
Tests: truncated huge messages while logging.
Diffstat (limited to '')
-rw-r--r--test/unit/http.py45
1 files changed, 33 insertions, 12 deletions
diff --git a/test/unit/http.py b/test/unit/http.py
index c71e8f7e..47fb48f1 100644
--- a/test/unit/http.py
+++ b/test/unit/http.py
@@ -96,12 +96,7 @@ class TestHTTP(TestUnit):
encoding = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding']
- if TestUnit.detailed:
- print('>>>')
- try:
- print(req.decode(encoding, 'ignore'))
- except UnicodeEncodeError:
- print(req)
+ self.log_out(req, encoding)
resp = ''
@@ -113,12 +108,7 @@ class TestHTTP(TestUnit):
sock, read_timeout=read_timeout, buff_size=read_buffer_size
).decode(encoding)
- if TestUnit.detailed:
- print('<<<')
- try:
- print(resp)
- except UnicodeEncodeError:
- print(resp.encode())
+ self.log_in(resp)
if 'raw_resp' not in kwargs:
resp = self._resp_to_dict(resp)
@@ -138,6 +128,37 @@ class TestHTTP(TestUnit):
return (resp, sock)
+ def log_out(self, log, encoding):
+ if TestUnit.detailed:
+ print('>>>')
+ log = self.log_truncate(log)
+ try:
+ print(log.decode(encoding, 'ignore'))
+ except UnicodeEncodeError:
+ print(log)
+
+ def log_in(self, log):
+ if TestUnit.detailed:
+ print('<<<')
+ log = self.log_truncate(log)
+ try:
+ print(log)
+ except UnicodeEncodeError:
+ print(log.encode())
+
+ def log_truncate(self, log, limit=1024):
+ len_log = len(log)
+ if len_log > limit:
+ log = log[:limit]
+ appendix = '(...logged %s of %s bytes)' % (limit, len_log)
+
+ if isinstance(log, bytes):
+ appendix = appendix.encode()
+
+ log = log + appendix
+
+ return log
+
def delete(self, **kwargs):
return self.http('DELETE', **kwargs)