[debhelper-devel] [debhelper] 07/21: Add test that enables/starts happen the expected number of times

Niels Thykier nthykier at moszumanska.debian.org
Fri Oct 13 18:27:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit 7d5c550901fe0eb53c8173bf0e0bc2b53b2ba6fd
Author: Felipe Sateler <fsateler at debian.org>
Date:   Wed Oct 4 18:27:29 2017 -0300

    Add test that enables/starts happen the expected number of times
---
 t/dh_installsystemd/dh_installsystemd.t | 40 +++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/t/dh_installsystemd/dh_installsystemd.t b/t/dh_installsystemd/dh_installsystemd.t
index e50fd99..ffe5825 100755
--- a/t/dh_installsystemd/dh_installsystemd.t
+++ b/t/dh_installsystemd/dh_installsystemd.t
@@ -12,6 +12,7 @@ our @TEST_DH_EXTRA_TEMPLATE_FILES = (qw(
     debian/changelog
     debian/control
     debian/foo.service
+    debian/foo2.service
 ));
 
 if (uid_0_test_is_ok()) {
@@ -20,10 +21,49 @@ if (uid_0_test_is_ok()) {
 	plan skip_all => 'fakeroot required';
 }
 
+sub unit_is_enabled {
+	my ($package, $unit, $num_enables) = @_;
+	my @output;
+	my $matches;
+	@output=`cat debian/$package.postinst.debhelper`;
+	$matches = grep { m{deb-systemd-helper enable .*$unit\.service} } @output;
+	ok($matches == $num_enables) or diag("$unit appears to have been enabled $matches times (expected $num_enables)");
+	@output=`cat debian/$package.postrm.debhelper`;
+	$matches = grep { m{deb-systemd-helper mask.*$unit\.service} } @output;
+	ok($matches == $num_enables) or diag("$unit appears to have been masked $matches times (expected $num_enables)");
+}
+sub unit_is_started {
+	my ($package, $unit, $num_starts) = @_;
+	my @output;
+	my $matches;
+	@output=`cat debian/$package.postinst.debhelper`;
+	$matches = grep { m{deb-systemd-invoke \$_dh_action .*$unit.service} } @output;
+	ok($matches == $num_starts) or diag("$unit appears to have been started $matches times (expected $num_starts)");
+	@output=`cat debian/$package.prerm.debhelper`;
+	$matches = grep { m{deb-systemd-invoke stop .*$unit.service} } @output;
+	ok($matches == $num_starts) or diag("$unit appears to have been started $matches times (expected $num_starts)");
+}
+
+# Units are installed and enabled
 each_compat_from_and_above_subtest(11, sub {
 	ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
 	ok(-e "debian/foo/lib/systemd/system/foo.service");
 	ok(-e "debian/foo.postinst.debhelper");
+	unit_is_enabled('foo', 'foo', 1);
+	unit_is_started('foo', 'foo', 1);
+	unit_is_enabled('foo', 'foo2', 0);
+	unit_is_started('foo', 'foo2', 1);
+	ok(run_dh_tool('dh_clean'));
+
+	make_path('debian/foo/lib/systemd/system/');
+	install_file('debian/foo2.service', 'debian/foo/lib/systemd/system/foo2.service');
+	ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_installsystemd'));
+	ok(-e "debian/foo/lib/systemd/system/foo.service");
+	ok(-e "debian/foo.postinst.debhelper");
+	unit_is_enabled('foo', 'foo', 1);
+	unit_is_started('foo', 'foo', 1);
+	unit_is_enabled('foo', 'foo2', 1);
+	unit_is_started('foo', 'foo2', 1);
 	ok(run_dh_tool('dh_clean'));
 });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list