MooseX::Daemonize::Core i think is done
[gitmo/MooseX-Daemonize.git] / t / 10.pidfile.t
CommitLineData
2eced271 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 25;
7use Test::Exception;
8
9BEGIN {
10 use_ok('MooseX::Daemonize::PidFile');
11}
12
13{
14 my $f = MooseX::Daemonize::PidFile->new(
15 file => [ 't', 'foo.pid' ]
16 );
17 isa_ok($f, 'MooseX::Daemonize::PidFile');
18
19 isa_ok($f->file, 'Path::Class::File');
20
21 is($f->pid, $$, '... the PID is our current process');
22
23 lives_ok {
24 $f->write
25 } '... writing the PID file';
26
27 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
28
29 ok($f->running, '... it is running too');
30
31 lives_ok {
32 $f->remove
33 } '... removing the PID file';
34
35 ok(!-e $f->file, '... the PID file does not exist anymore');
36}
37
38{
39 my $f = MooseX::Daemonize::PidFile->new(
40 file => [ 't', 'bar.pid' ]
41 );
42 isa_ok($f, 'MooseX::Daemonize::PidFile');
43
44 isa_ok($f->file, 'Path::Class::File');
45
46 lives_ok {
47 $f->write
48 } '... writing the PID file';
49
50 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
51 is($f->pid, $$, '... the PID is our current process');
52
53 ok($f->running, '... it is running too');
54
55 lives_ok {
56 $f->remove
57 } '... removing the PID file';
58
59 ok(!-e $f->file, '... the PID file does not exist anymore');
60}
61
62{
63 my $PID = 2001;
64
65 my $f = MooseX::Daemonize::PidFile->new(
66 file => [ 't', 'baz.pid' ],
67 pid => $PID,
68 );
69 isa_ok($f, 'MooseX::Daemonize::PidFile');
70
71 isa_ok($f->file, 'Path::Class::File');
72
73 is($f->pid, $PID, '... the PID is our made up PID');
74
75 lives_ok {
76 $f->write
77 } '... writing the PID file';
78
79 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
80
81 ok(!$f->running, '... it is not running (cause we made the PID up)');
82
83 lives_ok {
84 $f->remove
85 } '... removing the PID file';
86
87 ok(!-e $f->file, '... the PID file does not exist anymore');
88}