diff options
author | Felipe Sateler <fsateler@debian.org> | 2017-10-04 18:27:29 -0300 |
---|---|---|
committer | Niels Thykier <niels@thykier.net> | 2017-10-13 18:08:29 +0000 |
commit | 7d5c550901fe0eb53c8173bf0e0bc2b53b2ba6fd (patch) | |
tree | d95711e898181c95d212d128edd2686f44e9a376 /t | |
parent | 34eef4098688037a5380a71e37b4ecf45a89519a (diff) | |
download | debhelper-7d5c550901fe0eb53c8173bf0e0bc2b53b2ba6fd.tar.gz |
Add test that enables/starts happen the expected number of times
Diffstat (limited to 't')
-rwxr-xr-x | t/dh_installsystemd/dh_installsystemd.t | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/t/dh_installsystemd/dh_installsystemd.t b/t/dh_installsystemd/dh_installsystemd.t index e50fd993..ffe58257 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')); }); |