File: 02_sleep_system.t

package info (click to toggle)
libdaemon-control-perl 0.001006-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 248 kB
  • ctags: 147
  • sloc: perl: 2,244; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,889 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
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;

my ( $file, $ilib );

# Let's make it so people can test in t/ or in the dist directory.
if ( -f 't/bin/02_sleep_system.pl' ) { # Dist Directory.
    $file = "t/bin/02_sleep_system.pl";
    $ilib = "lib";
} elsif ( -f 'bin/02_sleep_system.pl' ) {
    $file = "bin/02_sleep_system.pl";
    $ilib = "../lib";
} else {
    die "Tests should be run in the dist directory or t/";
}


sub get_command_output {
    my ( @command ) = @_;
    open my $lf, "-|", @command
        or die "Couldn't get pipe to '@command': $!";
    my $content = do { local $/; <$lf> };
    close $lf;
    return $content;
}

my $out;

ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started system daemon";
like $out, qr/\[Started\]/, "Daemon started.";
ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Running\]/, "Daemon running.";

sleep 10;

ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Not Running\]/, "Daemon not running.";

# Testing restart.
ok $out = get_command_output( "$^X -I$ilib $file start" ), "Started system daemon";
like $out, qr/\[Started\]/, "Daemon started for restarting";
ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Running\]/, "Daemon running for restarting.";
ok $out = get_command_output( "$^X -I$ilib $file restart" ), "Get status of system daemon.";
like $out, qr/\[Stopped\].*\[Started\]/s, "Daemon restarted.";
ok $out = get_command_output( "$^X -I$ilib $file status" ), "Get status of system daemon.";
like $out, qr/\[Running\]/, "Daemon running after restart.";
ok $out = get_command_output( "$^X -I$ilib $file stop" ), "Get status of system daemon.";
like $out, qr/\[Stopped\]/, "Daemon stopped after restart.";

done_testing;