summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2024-11-07 13:08:53 +0800
committerZhidao HONG <z.hong@f5.com>2024-11-14 09:43:49 +0800
commita35517901fb3c7d524739fc4fcf9e531d6404487 (patch)
tree212d8b6a4e0779b7d7d0c34fc5d88f3db27c2ebe
parentbc838c5e1b6270c5195c4bdaa6a0a4bb72e48549 (diff)
downloadunit-a35517901fb3c7d524739fc4fcf9e531d6404487.tar.gz
unit-a35517901fb3c7d524739fc4fcf9e531d6404487.tar.bz2
tests: Add tests for JSON format access log
-rw-r--r--test/test_access_log.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/test_access_log.py b/test/test_access_log.py
index 1b0ec8ad..47099bd0 100644
--- a/test/test_access_log.py
+++ b/test/test_access_log.py
@@ -298,6 +298,12 @@ def test_access_log_format(wait_for_record):
check_format(log_format, log_format)
check_format('$uri $status $uri $status', '/ 200 / 200')
+ log_format = {
+ 'status': '$status',
+ 'uri': '$uri'
+ }
+ check_format(log_format, '{"status":"200","uri":"/"}')
+
def test_access_log_variables(wait_for_record):
load('mirror')
@@ -368,6 +374,24 @@ def test_access_log_if_njs(require, search_in_file, wait_for_record):
assert search_in_file(r'^/foo_2$', 'access.log') is None
+def test_access_log_format_njs(require, search_in_file, wait_for_record):
+ require({'modules': {'njs': 'any'}})
+
+ load('empty')
+
+ def check_format(log_format, expect, url='/'):
+ set_format(log_format)
+
+ assert client.get(url=url)['status'] == 200
+ assert wait_for_record(expect, 'access.log') is not None, 'found'
+
+ log_format = {
+ 'status': '$status',
+ 'uri': '`${vars.uri}`'
+ }
+ check_format(log_format, '{"status":"200","uri":"/"}')
+
+
def test_access_log_incorrect(temp_dir, skip_alert):
skip_alert(r'failed to apply new conf')