Commit af9ab301 authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Provide assertLastLogLineRegexp method

parent cf89ce81
...@@ -1201,6 +1201,16 @@ class SlaveHttpFrontendTestCase(HttpFrontendTestCase): ...@@ -1201,6 +1201,16 @@ class SlaveHttpFrontendTestCase(HttpFrontendTestCase):
return parameter_dict return parameter_dict
def assertLastLogLineRegexp(self, log_name, log_regexp):
log_file = glob.glob(
os.path.join(
self.instance_path, '*', 'var', 'log', 'httpd', log_name
))[0]
self.assertRegexpMatches(
open(log_file, 'r').readlines()[-1],
log_regexp)
class TestMasterRequestDomain(HttpFrontendTestCase, TestDataMixin): class TestMasterRequestDomain(HttpFrontendTestCase, TestDataMixin):
@classmethod @classmethod
...@@ -1891,38 +1901,24 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -1891,38 +1901,24 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
result.headers['Set-Cookie'] result.headers['Set-Cookie']
) )
# check access log self.assertLastLogLineRegexp(
log_file = glob.glob( '_Url_access_log',
os.path.join( r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} - - '
self.instance_path, '*', 'var', 'log', 'httpd', '_Url_access_log' r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2} \+\d{4}\] '
))[0] r'"GET \/test-path\/deep\/..\/.\/deeper HTTP\/1.1" \d{3} '
log_regexp = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} - - ' \
r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2} \+\d{4}\] ' \
r'"GET \/test-path\/deep\/..\/.\/deeper HTTP\/1.1" \d{3} ' \
r'\d+ "-" "TEST USER AGENT" \d+' r'\d+ "-" "TEST USER AGENT" \d+'
)
self.assertRegexpMatches( self.assertLastLogLineRegexp(
open(log_file, 'r').readlines()[-1], '_Url_backend_log',
log_regexp) r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+ '
r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2}.\d{3}\] '
# check backend log r'http-backend _Url-http\/_Url-backend '
log_file = glob.glob( r'\d+/\d+\/\d+\/\d+\/\d+ '
os.path.join( r'200 \d+ - - ---- '
self.instance_path, '*', 'var', 'log', 'httpd', '_Url_backend_log' r'\d+\/\d+\/\d+\/\d+\/\d+ \d+\/\d+ '
))[0]
log_regexp = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+ ' \
r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2}.\d{3}\] ' \
r'http-backend _Url-http\/_Url-backend ' \
r'\d+/\d+\/\d+\/\d+\/\d+ ' \
r'200 \d+ - - ---- ' \
r'\d+\/\d+\/\d+\/\d+\/\d+ \d+\/\d+ ' \
r'"GET /test-path/deeper HTTP/1.1"' r'"GET /test-path/deeper HTTP/1.1"'
)
self.assertRegexpMatches(
open(log_file, 'r').readlines()[-1],
log_regexp)
result_http = fakeHTTPResult( result_http = fakeHTTPResult(
parameter_dict['domain'], parameter_dict['domain'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment