Bug 40901: Add systemd unit file validation test

Adds t/00-valid-systemd-units.t which runs systemd-analyze verify
against every unit file in debian/systemd/. Skips gracefully if
systemd-analyze is not installed (requires the systemd package).

To enable this test in KTD-based CI, add 'systemd' to the KTD
container's package list. systemd-analyze verify does not require
systemd to be running as PID 1 — it is pure static analysis and
works correctly in a standard Docker container.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-05-22 07:53:54 +01:00 committed by Pedro Amorim
parent 3eb65c1041
commit 6b54ee976b
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 48 additions and 0 deletions

48
t/00-valid-systemd-units.t Executable file
View File

@ -0,0 +1,48 @@
# Copyright 2026 Martin Renvoize
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More;
use Cwd qw( abs_path );
use FindBin qw( $Bin );
my $analyzer = qx(which systemd-analyze 2>/dev/null);
chomp $analyzer;
plan( skip_all => 'systemd-analyze not found; install the systemd package' )
unless $analyzer;
my $units_dir = abs_path("$Bin/../debian/systemd");
plan( skip_all => 'debian/systemd not found' )
unless $units_dir && -d $units_dir;
opendir( my $dh, $units_dir ) or die "Cannot open $units_dir: $!";
my @units =
sort
grep { /\.(service|target|socket|timer)$/ }
readdir $dh;
closedir $dh;
plan( skip_all => 'No unit files found in debian/systemd' ) unless @units;
plan tests => scalar @units;
for my $unit (@units) {
my $output = qx(systemd-analyze verify --no-pager "--unit-path=$units_dir" $unit 2>&1);
my $rc = $? >> 8;
ok( $rc == 0, "Valid unit file: $unit" ) or diag $output;
}