prep for release
[catagits/Catalyst-Plugin-Scheduler.git] / t / 06trigger.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8 use Test::More;
9 use Storable qw/lock_store lock_retrieve/;
10
11 plan tests => 6;
12 use Catalyst::Test 'TestApp';
13
14 our $STATE = "$FindBin::Bin/lib/TestApp/scheduler.state";
15
16 TestApp->schedule(
17     trigger  => 'every_minute',
18     event    => '/cron/every_minute',
19 );
20
21 # disallow localhost
22 TestApp->config->{scheduler}->{hosts_allow} = '1.2.3.4';
23
24 # test that the event does not execute
25 {
26     ok( my $res = request('http://localhost/?schedule_trigger=every_minute'), 'request ok' );
27     is( $res->content, 'default', 'response ok' );
28     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", undef, 'every_minute did not execute, ok' );
29     unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
30 }
31
32 # allow localhost
33 TestApp->config->{scheduler}->{hosts_allow} = [ '1.2.3.4', '127.0.0.1' ];
34
35 # test that the event does execute
36 {
37     ok( my $res = request('http://localhost/?schedule_trigger=every_minute'), 'request ok' );
38     is( $res->content, 'default', 'response ok' );
39     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", 1, 'every_minute executed ok' );
40     unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
41 }