From s.ivanov at proxmox.com Fri Jan 2 21:32:01 2026 From: s.ivanov at proxmox.com (Stoiko Ivanov) Date: Fri, 2 Jan 2026 21:32:01 +0100 Subject: [pmg-devel] [PATCH pmg-api 3/3] tests: conditionally skip integration tests In-Reply-To: <20260102203253.28218-1-s.ivanov@proxmox.com> References: <20260102203253.28218-1-s.ivanov@proxmox.com> Message-ID: <20260102203253.28218-4-s.ivanov@proxmox.com> By setting the SKIP_INTEGRATION_TESTS (environment or Makefile variable) to a non-empty value the integration-tests are skipped. To skip them in sbuild - check for the existance of /run/lock/sbuild (inspired by pve-container's `src/test/Makefile`) with realpath[0], which returns an empty string for a non-existing file. tested by running `make sbuild`, `make deb` and `SKIP_INTEGRATION_TESTS=y make deb`. [0] https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html#index-realpath-1 Suggested-by: Fabian Gr?nbichler Signed-off-by: Stoiko Ivanov --- src/tests/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tests/Makefile b/src/tests/Makefile index 3d5b0179..20833b4d 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1,9 +1,16 @@ export PERLLIB = .. +# realpath returns an empty string for non-existing files +SKIP_INTEGRATION_TESTS ?= $(realpath /run/lock/sbuild) + all: .PHONY: check +ifeq ($(strip $(SKIP_INTEGRATION_TESTS)),) check: test-utils test-sa-channel integration-tests +else +check: test-utils test-sa-channel +endif .PHONY: test-utils test-utils: -- 2.47.3 From s.ivanov at proxmox.com Fri Jan 2 21:32:00 2026 From: s.ivanov at proxmox.com (Stoiko Ivanov) Date: Fri, 2 Jan 2026 21:32:00 +0100 Subject: [pmg-devel] [PATCH pmg-api 2/3] tests: make test nature explicit In-Reply-To: <20260102203253.28218-1-s.ivanov@proxmox.com> References: <20260102203253.28218-1-s.ivanov@proxmox.com> Message-ID: <20260102203253.28218-3-s.ivanov@proxmox.com> Most of the tests in PMG's test-suite are integration tests in nature - they create a database, set the default ruleset and compare it, or run tests against a running pmgpolicy daemon. The two test-suites that are closer to unit-tests are test_utils.pl and ./test_sa_channel_parser.pl. This patch refactors the Makefile (and drops a few commented out lines) to make this distinction explicit, in preparation for only running unit-tests in restricted build-environments (e.g. sbuild). No functional change intended. Suggested-by: Fabian Gr?nbichler Signed-off-by: Stoiko Ivanov --- src/tests/Makefile | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/tests/Makefile b/src/tests/Makefile index 68f77e4d..3d5b0179 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1,26 +1,25 @@ -#export TESTDB = "Proxmox_testdb" - export PERLLIB = .. all: .PHONY: check -check: test-utils +check: test-utils test-sa-channel integration-tests + +.PHONY: test-utils +test-utils: + ./test_utils.pl + +.PHONY: test-sa-channel +test-sa-channel: + ./test_sa_channel_parser.pl + +.PHONY: integration-tests +integration-tests: ./create_testdb.pl ./init_testdb.pl ./print_testdb.pl > testdb.txt.new diff -u testdb.txt testdb.txt.new ./test_greylist.pl - ./test_sa_channel_parser.pl - -# test_config.pl \ -# test_mimetype.pl \ -# test_proxy.pl \ -# test_unpack.pl - -.PHONY: test-utils -test-utils: - ./test_utils.pl clean: rm -rf *~ proxytest_report.out test.cfg testdb.txt.new -- 2.47.3 From s.ivanov at proxmox.com Fri Jan 2 21:31:58 2026 From: s.ivanov at proxmox.com (Stoiko Ivanov) Date: Fri, 2 Jan 2026 21:31:58 +0100 Subject: [pmg-devel] [PATCH pmg-api 0/3] enable building with sbuild, by refactoring tests Message-ID: <20260102203253.28218-1-s.ivanov@proxmox.com> Building pmg-api in sbuild is currently not possible, due to 2 issues: * the format_date_header tests in test_util.pl implicitly assume a CET/CEST timezone (patch 1/3) * most other tests in pmg-api are integration-tests - they create postgres databases, dump them, start services, and expect syslog to work. this is changed by skipping the tests conditionally (with the condition evaluating to true in an sbuild environment) I considered reworking the tests on the database to output a stable text file for comparison (the output of `pmgdb dump` would work), but the RuleDB code is tightly coupled to writing to the database - changing that would amount to a far larger refactoring of pmg-api. So instead leave the default build calls most of us working with pmg-api as they are and skip the tests in sbuild (or by setting an environment variable). checking out autopkgtests for the other tests is probably a good idea - but should not prevent us from having a working sbuild target for pmg-api. Stoiko Ivanov (3): tests: test_utils: do not rely on system timezone tests: make test nature explicit tests: conditionally skip integration tests src/tests/Makefile | 32 +++++++++++++++++++------------- src/tests/test_utils.pl | 5 ++++- 2 files changed, 23 insertions(+), 14 deletions(-) -- 2.47.3 From s.ivanov at proxmox.com Fri Jan 2 21:31:59 2026 From: s.ivanov at proxmox.com (Stoiko Ivanov) Date: Fri, 2 Jan 2026 21:31:59 +0100 Subject: [pmg-devel] [PATCH pmg-api 1/3] tests: test_utils: do not rely on system timezone In-Reply-To: <20260102203253.28218-1-s.ivanov@proxmox.com> References: <20260102203253.28218-1-s.ivanov@proxmox.com> Message-ID: <20260102203253.28218-2-s.ivanov@proxmox.com> the tests for format_date_header inherently rely on a timezone being set (as the date-format in mail-headers expects one). running the test in a build-environment like sbuild, which has the timezone set to UTC fails. fix this by explicitly setting the timezone to 'Europe/Vienna'. Suggested-by: Fabian Gr?nbichler Signed-off-by: Stoiko Ivanov --- src/tests/test_utils.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tests/test_utils.pl b/src/tests/test_utils.pl index 8abcc8b7..ff856ebe 100755 --- a/src/tests/test_utils.pl +++ b/src/tests/test_utils.pl @@ -4,10 +4,13 @@ use strict; use warnings; use Test::More; -use POSIX qw(setlocale strftime); +use POSIX qw(setlocale strftime tzset); use PMG::Utils; +$ENV{TZ} = 'Europe/Vienna'; +tzset(); + subtest 'format_date_header works' => sub { cmp_ok(length(PMG::Utils::format_date_header(localtime())), '>=', 30); is( -- 2.47.3