diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:15:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:15:44 +0000 |
commit | 1a42a93b11c48e696446250f2a1f1ca71b350e9b (patch) | |
tree | 900e3702d59f6d7cae8f7def94ed5194602f6846 /t/dh_installsystemduser | |
parent | Initial commit. (diff) | |
download | debhelper-1a42a93b11c48e696446250f2a1f1ca71b350e9b.tar.xz debhelper-1a42a93b11c48e696446250f2a1f1ca71b350e9b.zip |
Adding upstream version 13.3.4.upstream/13.3.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 't/dh_installsystemduser')
-rw-r--r-- | t/dh_installsystemduser/debian/baz.user.service | 8 | ||||
-rw-r--r-- | t/dh_installsystemduser/debian/changelog | 5 | ||||
-rw-r--r-- | t/dh_installsystemduser/debian/control | 10 | ||||
-rw-r--r-- | t/dh_installsystemduser/debian/foo.user.service | 8 | ||||
-rw-r--r-- | t/dh_installsystemduser/dh_installsystemduser.t | 75 |
5 files changed, 106 insertions, 0 deletions
diff --git a/t/dh_installsystemduser/debian/baz.user.service b/t/dh_installsystemduser/debian/baz.user.service new file mode 100644 index 0000000..3af041d --- /dev/null +++ b/t/dh_installsystemduser/debian/baz.user.service @@ -0,0 +1,8 @@ +[Unit] +Description=Baz User Unit + +[Service] +ExecStart=/bin/true + +[Install] +WantedBy=default.target diff --git a/t/dh_installsystemduser/debian/changelog b/t/dh_installsystemduser/debian/changelog new file mode 100644 index 0000000..5850f0e --- /dev/null +++ b/t/dh_installsystemduser/debian/changelog @@ -0,0 +1,5 @@ +foo (1.0-1) unstable; urgency=low + + * Initial release. (Closes: #XXXXXX) + + -- Test <testing@nowhere> Mon, 11 Jul 2016 18:10:59 +0200 diff --git a/t/dh_installsystemduser/debian/control b/t/dh_installsystemduser/debian/control new file mode 100644 index 0000000..adccbc6 --- /dev/null +++ b/t/dh_installsystemduser/debian/control @@ -0,0 +1,10 @@ +Source: foo +Section: misc +Priority: optional +Maintainer: Test <testing@exampe.org> +Standards-Version: 3.9.8 + +Package: foo +Architecture: all +Description: package foo + Package foo diff --git a/t/dh_installsystemduser/debian/foo.user.service b/t/dh_installsystemduser/debian/foo.user.service new file mode 100644 index 0000000..7ef597d --- /dev/null +++ b/t/dh_installsystemduser/debian/foo.user.service @@ -0,0 +1,8 @@ +[Unit] +Description=Foo User Unit + +[Service] +ExecStart=/bin/true + +[Install] +WantedBy=default.target diff --git a/t/dh_installsystemduser/dh_installsystemduser.t b/t/dh_installsystemduser/dh_installsystemduser.t new file mode 100644 index 0000000..894eeb7 --- /dev/null +++ b/t/dh_installsystemduser/dh_installsystemduser.t @@ -0,0 +1,75 @@ +#!/usr/bin/perl +use strict; +use Test::More; +use File::Path qw(make_path); +use File::Basename qw(dirname); +use lib dirname(dirname(__FILE__)); +use Test::DH; +use Debian::Debhelper::Dh_Lib qw(!dirname); + +plan(tests => 1); + +our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw( + debian/changelog + debian/control + debian/foo.user.service + debian/baz.user.service +)); + + +sub read_script { + my ($package, $name) = @_; + my @lines; + + foreach my $script (find_script($package, $name)) { + open(my $fh, '<', $script) or die("open($script): $!"); + push @lines, $_ for <$fh>; + close($fh); + } + + return @lines; +} + +sub _unit_check_user_enabled { + my ($package, $unit, $enabled) = @_; + my $verb = $enabled ? "is" : "isnt"; + my $matches; + + my @postinst = read_script($package, 'postinst'); + # Match exactly one tab character. The "dont-enable" script has + # an "enable" line for re-enabling the service if the admin had it + # enabled, but we do not want to include that in our count. + $matches = grep { m{^\tif deb-systemd-helper( --\w+)* --user was-enabled.*'\Q$unit'} } @postinst; + is($matches, $enabled, "$unit $verb enabled"); + + my @postrm = read_script($package, 'postrm'); + $matches = grep { m{deb-systemd-helper( --\w+)* --user mask.*'\Q$unit'} } @postrm; + is($matches, $enabled, "$unit $verb masked"); +} + +sub is_enabled { _unit_check_user_enabled(@_, 1); } +sub isnt_enabled { _unit_check_user_enabled(@_, 0); } + +each_compat_subtest { + make_path('debian/foo/usr/lib/systemd/user/'); + install_file('debian/foo.user.service', 'debian/foo/usr/lib/systemd/user/bar.service'); + ok(run_dh_tool('dh_installsystemduser')); + ok(-e 'debian/foo/usr/lib/systemd/user/foo.service'); + is_enabled('foo', 'foo.service'); + is_enabled('foo', 'bar.service'); + ok(run_dh_tool('dh_clean')); + + ok(run_dh_tool('dh_installsystemduser')); + ok(-e 'debian/foo/usr/lib/systemd/user/foo.service'); + ok(! -e 'debian/foo/usr/lib/systemd/user/baz.service'); + is_enabled('foo', 'foo.service'); + isnt_enabled('foo', 'baz.service'); + ok(run_dh_tool('dh_clean')); + + ok(run_dh_tool('dh_installsystemduser', '--name', 'baz')); + ok(! -e 'debian/foo/usr/lib/systemd/user/foo.service'); + ok(-e 'debian/foo/usr/lib/systemd/user/baz.service'); + isnt_enabled('foo', 'foo.service'); + is_enabled('foo', 'baz.service'); + ok(run_dh_tool('dh_clean')); +}; |