Skip to content

Commit

Permalink
tests: Add tests for JSON format access log
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhidao committed Nov 14, 2024
1 parent bc838c5 commit a355179
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/test_access_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ def check_format(log_format, expect, url='/'):
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')
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit a355179

Please sign in to comment.