File: systemd-service.t

package info (click to toggle)
libconfig-model-systemd-perl 0.257.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,084 kB
  • sloc: perl: 13,439; makefile: 12
file content (91 lines) | stat: -rw-r--r-- 2,075 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- cperl -*-
use strict;
use warnings;
use English;
use Path::Tiny;

use Test::More;
use Test::File::Contents;
use Test::Log::Log4perl;
use Config::Model qw/cme/;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;


my ($model, $trace) = init_test();

# pseudo root where config files are written by config-model
my $wr_root = setup_test_dir;

my $lib_systemd = $wr_root->child('lib/systemd/system/');
$lib_systemd->mkpath({mode => oct(755)});
$lib_systemd->child('transmission-daemon.service')->spew(<DATA>);

my $inst = $model->instance (
    application       => 'systemd',
    instance_name     => 'instance',
    root_dir          => $wr_root,
    backend_arg       => 'transmission-daemon',
);

ok($inst,"Created instance") ;

my $root = $inst -> config_root ;

my $dump;
{
    my $xp = Test::Log::Log4perl->expect(
        ignore_priority => "info",
        [
            'User',
            warn =>  qr/Unexpected systemd parameter/
        ]
    );
    $dump = $root->dump_tree (mode => 'full');
}
ok($dump,"Created dump") ;

print "First dump:\n",$dump if $trace ;

$root -> load("service:transmission-daemon Unit After:<you") ;
ok(1,"loaded data") ;

$inst->write_back;
ok(1,"wrote data back") ;

my $service_dot_d = $wr_root->child('etc/systemd/system/transmission-daemon.service.d');

file_contents_like(
    $service_dot_d->child('override.conf')->stringify,
    qr/you/,
    "override file was written",
);

$root -> load("service:transmission-daemon Unit After:-=you") ;

$inst->write_back;

ok(! $service_dot_d->child('override.conf')->exists, "unneeded file was removed");
ok(! $service_dot_d->exists, "unneeded dir was removed");

done_testing;

__END__
__DATA__

[Unit]
Description=Transmission BitTorrent Daemon
After=network.target

[Service]
User=debian-transmission
Type=notify
ExecStart=/usr/bin/transmission-daemon -f --log-error
ExecStop=/bin/kill -s STOP $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
# test conversion of on to no
NoNewPrivileges=on
# test accepted parameters
DummyParam=dummy

[Install]
WantedBy=multi-user.target