Changes:
[catagits/Catalyst-Plugin-Scheduler.git] / t / 05auto_run.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8 use Test::More tests => 6;
9 use Catalyst::Test 'TestApp';
10
11 our $STATE = "$FindBin::Bin/lib/TestApp/scheduler.state";
12 our $BASE  = 'Catalyst::Plugin::Scheduler::Base';
13
14 # hack the last event check to make all events execute immediately
15 $BASE->_last_check_time( 0 );
16
17 TestApp->schedule(
18     at       => '* * * * *',
19     event    => '/cron/every_minute',
20     auto_run => 0,
21 );
22
23
24 # disallow localhost
25 TestApp->config->{scheduler}->{hosts_allow} = '1.2.3.4';
26
27 # test that the event does not execute
28 {
29     ok( my $res = request('http://localhost/'), 'request ok' );
30     is( $res->content, 'default', 'response ok' );
31     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", undef, 'every_minute did not execute, ok' );
32     unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
33 }
34
35 # hack the last event check to make all events execute immediately
36 $BASE->_last_check_time( 0 );
37
38 # allow localhost
39 TestApp->config->{scheduler}->{hosts_allow} = [ '1.2.3.4', '127.0.0.1' ];
40
41 # test that the event does execute
42 {
43     ok( my $res = request('http://localhost/'), 'request ok' );
44     is( $res->content, 'default', 'response ok' );
45     is( -e "$FindBin::Bin/lib/TestApp/every_minute.log", 1, 'every_minute executed ok' );
46     unlink "$FindBin::Bin/lib/TestApp/every_minute.log";
47 }