File: cme-function.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 (63 lines) | stat: -rw-r--r-- 1,606 bytes parent folder | download | duplicates (2)
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
# -*- cperl -*-
use strict;
use warnings;
use English;
use Path::Tiny;

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

if ($OSNAME eq 'solaris' ) {
    plan skip_all => "Test irrelevant on $OSNAME";
    exit;
}

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

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

my $systemd_file = $wr_root->child('test.service');

subtest 'create file from scratch' => sub {

    my $instance = cme(
        application => 'systemd-service-file',
        config_file => $systemd_file->basename,
        root_dir => $wr_root->stringify
    );

    ok($instance, "systemd-service instance created");

    $instance->modify('Unit Description="test single unit"');
    # test minimal modif (re-order)
    $instance->save(force => 1);
    ok(1,"data saved");

    file_contents_like($systemd_file->stringify, qr/test single unit/,"saved file ok");
};

subtest 'read file with basename' => sub {
    my $instance = cme(
        application => 'systemd-service-file',
        config_file => $systemd_file->basename,
        root_dir => $wr_root->stringify
    );

    is($instance->grab_value('Unit Description'),"test single unit","read file ok");
};

subtest 'read file with service suffix' => sub {
    my $instance = cme(
        application => 'systemd-service-file',
        config_file => $systemd_file,
        root_dir => $wr_root->stringify
    );

    is($instance->grab_value('Unit Description'),"test single unit","read file ok");
};

done_testing();