From 618e47799afdfc2783d8469ca909aafa4acfa7b6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 19:29:54 +0200 Subject: Adding upstream version 1.66. Signed-off-by: Daniel Baumann --- t/003-deb-systemd-helper-complex.t | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 t/003-deb-systemd-helper-complex.t (limited to 't/003-deb-systemd-helper-complex.t') diff --git a/t/003-deb-systemd-helper-complex.t b/t/003-deb-systemd-helper-complex.t new file mode 100644 index 0000000..47d8fb4 --- /dev/null +++ b/t/003-deb-systemd-helper-complex.t @@ -0,0 +1,123 @@ +#!perl +# vim:ts=4:sw=4:et + +use strict; +use warnings; +use Test::More; +use Test::Deep qw(:preload cmp_bag); +use File::Temp qw(tempfile tempdir); # in core since perl 5.6.1 +use File::Path qw(make_path); # in core since Perl 5.001 +use File::Basename; # in core since Perl 5 +use FindBin; # in core since Perl 5.00307 + +use lib "$FindBin::Bin/."; +use helpers; + +test_setup(); + +my $dpkg_root = $ENV{DPKG_ROOT} // ''; + +# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +# ┃ Create two unit files with random names; they refer to each other (Also=).┃ +# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +my ($fh1, $random_unit1) = tempfile('unitXXXXX', + SUFFIX => '.service', + TMPDIR => 1, + UNLINK => 1); +close($fh1); +$random_unit1 = basename($random_unit1); + +my ($fh2, $random_unit2) = tempfile('unitXXXXX', + SUFFIX => '.service', + TMPDIR => 1, + UNLINK => 1); +close($fh2); +$random_unit2 = basename($random_unit2); + +my $servicefile_path1 = "$dpkg_root/lib/systemd/system/$random_unit1"; +my $servicefile_path2 = "$dpkg_root/lib/systemd/system/$random_unit2"; +make_path("$dpkg_root/lib/systemd/system"); +open($fh1, '>', $servicefile_path1); +print $fh1 <', $servicefile_path2); +print $fh2 < $servicefile_path1, + $random_unit2 => $servicefile_path2, + }, + 'All expected links present'); + +my $alias_path = "$dpkg_root/etc/systemd/system/alias2.service"; +ok(-l $alias_path, 'alias created'); +is($dpkg_root . readlink($alias_path), $servicefile_path2, + 'alias points to the correct service file'); + +cmp_bag( + [ state_file_entries("$dpkg_root/var/lib/systemd/deb-systemd-helper-enabled/$random_unit1.dsh-also") ], + [ "$dpkg_root/etc/systemd/system/multi-user.target.wants/$random_unit1", + "$dpkg_root/etc/systemd/system/multi-user.target.wants/$random_unit2", + "$dpkg_root/etc/systemd/system/alias2.service" ], + 'state file updated'); + +# ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +# ┃ Verify “is-enabled” now returns true. ┃ +# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +is_enabled($random_unit1); +is_enabled($random_unit2); +is_debian_installed($random_unit1); + +# $random_unit2 was only enabled _because of_ $random_unit1’s Also= statement +# and thus does not have its own state file. +isnt_debian_installed($random_unit2); + +# TODO: cleanup tests? + +done_testing; -- cgit v1.2.3