mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: support LOG_CONFIG environment variable
This variable allows users to override the logging.conf used for Python logging configuration. By default, this is set to logging.conf, which is a production config. LOG_CONFIG is treated relative to [options] aurwebdir. This patch allows us to specify the logging config as opposed to copying over logging.conf in our test docker and gitlab test scripts, as well as ease-of-testing as a developer. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
7f1de72e08
commit
7bcc8d7ce7
6 changed files with 16 additions and 12 deletions
|
@ -10,6 +10,7 @@ variables:
|
|||
DB_HOST: localhost
|
||||
TEST_RECURSION_LIMIT: 10000
|
||||
CURRENT_DIR: "$(pwd)"
|
||||
LOG_CONFIG: logging.test.conf
|
||||
|
||||
test:
|
||||
stage: test
|
||||
|
@ -26,15 +27,14 @@ test:
|
|||
- cp -v conf/config.dev conf/config
|
||||
- sed -i "s;YOUR_AUR_ROOT;$(pwd);g" conf/config
|
||||
- ./docker/test-mysql-entrypoint.sh # Create mysql AUR_CONFIG.
|
||||
- cp -vf logging.test.conf logging.conf # Put test logging config in place.
|
||||
- make -C po all install # Compile translations.
|
||||
- make -C doc # Compile asciidoc.
|
||||
- make -C test clean # Cleanup coverage.
|
||||
script:
|
||||
# Run sharness.
|
||||
- make -C test sh # sharness tests use sqlite.
|
||||
- make -C test sh
|
||||
# Run pytest.
|
||||
- pytest # Run pytest suites.
|
||||
- pytest
|
||||
- make -C test coverage # Produce coverage reports.
|
||||
- flake8 --count aurweb # Assert no flake8 violations in aurweb.
|
||||
- flake8 --count test # Assert no flake8 violations in test.
|
||||
|
|
|
@ -4,8 +4,11 @@ import os
|
|||
|
||||
import aurweb.config
|
||||
|
||||
# For testing, users should set LOG_CONFIG=logging.test.conf
|
||||
# We test against various debug log output.
|
||||
aurwebdir = aurweb.config.get("options", "aurwebdir")
|
||||
config_path = os.path.join(aurwebdir, "logging.conf")
|
||||
log_config = os.environ.get("LOG_CONFIG", "logging.conf")
|
||||
config_path = os.path.join(aurwebdir, log_config)
|
||||
|
||||
logging.config.fileConfig(config_path, disable_existing_loggers=False)
|
||||
logging.getLogger("root").addHandler(logging.NullHandler())
|
||||
|
@ -19,4 +22,5 @@ def get_logger(name: str) -> logging.Logger:
|
|||
:param name: Logger name; typically `__name__`
|
||||
:returns: name's logging.Logger
|
||||
"""
|
||||
|
||||
return logging.getLogger(name)
|
||||
|
|
|
@ -273,6 +273,7 @@ services:
|
|||
init: true
|
||||
environment:
|
||||
- AUR_CONFIG=conf/config.sqlite
|
||||
- LOG_CONFIG=logging.test.conf
|
||||
entrypoint: /docker/sharness-entrypoint.sh
|
||||
command: /docker/scripts/run-sharness.sh
|
||||
stdin_open: true
|
||||
|
@ -298,6 +299,7 @@ services:
|
|||
- AUR_CONFIG=conf/config
|
||||
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
||||
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
|
||||
- LOG_CONFIG=logging.test.conf
|
||||
entrypoint: /docker/test-mysql-entrypoint.sh
|
||||
command: /docker/scripts/run-pytests.sh clean
|
||||
stdin_open: true
|
||||
|
@ -326,6 +328,7 @@ services:
|
|||
- AUR_CONFIG=conf/config
|
||||
- TEST_RECURSION_LIMIT=${TEST_RECURSION_LIMIT}
|
||||
- PROMETHEUS_MULTIPROC_DIR=/tmp_prometheus
|
||||
- LOG_CONFIG=logging.test.conf
|
||||
entrypoint: /docker/test-mysql-entrypoint.sh
|
||||
command: /docker/scripts/run-tests.sh
|
||||
stdin_open: true
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
cp -vf logging.prod.conf logging.conf
|
||||
|
||||
exec "$@"
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -eou pipefail
|
||||
|
||||
# Set test logging.
|
||||
cp -vf "logging.test.conf" "logging.conf"
|
||||
|
||||
# We use the root user for testing in Docker.
|
||||
# The test user must be able to create databases and drop them.
|
||||
aurweb-config set database user 'root'
|
||||
|
|
|
@ -24,9 +24,10 @@ Logging
|
|||
-------
|
||||
|
||||
Tests also require the `logging.test.conf` logging configuration
|
||||
file to be used. To prepare, you can override `logging.conf`:
|
||||
file to be used. You can specify the `LOG_CONFIG` environment
|
||||
variable to override:
|
||||
|
||||
$ cp -vf logging.test.conf logging.conf
|
||||
$ export LOG_CONFIG=logging.test.conf
|
||||
|
||||
`logging.test.conf` enables debug logging for the aurweb package,
|
||||
for which we run tests against.
|
||||
|
@ -85,9 +86,10 @@ Run tests from the project root.
|
|||
|
||||
$ cd /path/to/aurweb
|
||||
|
||||
Ensure you have the proper `AUR_CONFIG` exported:
|
||||
Ensure you have the proper `AUR_CONFIG` and `LOG_CONFIG` exported:
|
||||
|
||||
$ export AUR_CONFIG=conf/config
|
||||
$ export LOG_CONFIG=logging.test.conf
|
||||
|
||||
To run `sharness` shell test suites (requires Arch Linux):
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue