Agent-TCLI

 view release on metacpan or  search on metacpan

t/TCLI.Package.Tail.t  view on Meta::CPAN

use strict;

use Getopt::Long;

# process options
my ($verbose,$poe_td,$poe_te);
eval { GetOptions (
  		"verbose+"		=> \$verbose,
  		"event_trace+"		=> \$poe_te,
  		"default_trace+"		=> \$poe_td,
)};
if($@) {die "ERROR: $@";}

$verbose = 0 unless defined($verbose);
$poe_td = 0 unless defined($poe_td);
$poe_te = 0 unless defined($poe_te);

sub POE::Kernel::TRACE_DEFAULT  () { $poe_td }
sub POE::Kernel::TRACE_EVENTS  () { $poe_te }
sub POE::Component::SimpleLog::DEBUG () { 0 }

use Agent::TCLI::Transport::Test;
use Agent::TCLI::Testee;
use POE;

use Agent::TCLI::Package::Tail;
#use_ok('Agent::TCLI::Package::Tail');


my $test1 = Agent::TCLI::Package::Tail->new({
	'verbose'		=> \$verbose,
	'do_verbose'	=> sub { diag( @_ ) },
	});


my $test_master = Agent::TCLI::Transport::Test->new({
    'verbose'   	=> \$verbose,        # Verbose sets level or warnings
	'do_verbose'	=> sub { diag( @_ ) },

    'control_options'	=> {
	     'packages' 	=> [ $test1, ],
    },

});

my $t = Agent::TCLI::Testee->new(
	'test_master'	=> $test_master,
	'addressee'		=> 'self',
);

is($test1->name,'tcli_tail', '$test1->Name ');
my $test_c1 = $test1->commands();
is(ref($test_c1),'HASH', '$test1->Commands is a hash');
my $test_c1_0 = $test_c1->{'tail'};
is($test_c1_0->name,'tail', '$test_c1_0->name get from init args');
is($test_c1_0->usage,'tail file add file /var/log/messages', '$test_c1_0->usage get from init args');
is($test_c1_0->help,'tail a file', '$test_c1_0->help get from init args');
is($test_c1_0->topic,'testing', '$test_c1_0->topic get from init args');
is($test_c1_0->command,'tcli_tail', '$test_c1_0->command get from init args');
is($test_c1_0->handler,'establish_context', '$test_c1_0->handler get from init args');
is($test_c1_0->call_style,'session', '$test_c1_0->call_style get from init args');


my $function;
# In these tests I am mostly testing body, because I am testing the Command.
# for real test scripts using tail, testing with ok should suffice.

$t->is_body( 'tail','Context now: tail', 'Initialize context');
$t->is_body( 'file','Context now: tail file', 'tail file context');
$t->ok( 'add file README ', 'added file');
$t->like_body( 'exit',qr(Context now: tail), "Exit ok");
$t->is_body( 'test','Context now: tail test', 'tail test context');

$t->like_body( 'add like="test one" name="test one"',qr(test.*?added), 'added test like one ');
$t->like_body('', qr(ok.*?test\sone), "passed test one");
$t->like_body( 'exit',qr(Context now: tail), "Exit ok");
$t->ok( 'log "9 test one"');

$function =  "like";
$t->like_body( 'test add like="test pass" name="test pass"',qr(test.*?added), "added test pass $function");
$t->is_code('', 200, "passed test pass $function");
$t->ok( 'log "12 test pass"');

$t->ok( 'clear lines');
$t->is_code('test add like="test fail" name="test fail" max_lines=1 ', 417, "failed test fail $function");
$t->ok( 'log "15 test"');
$test_master->done(31, "finish testing $function" );

# Must clear out the line still in the cache from the prior fail.
$t->ok( 'clear lines');

$function =  "max_lines";
$t->like_body( 'test add like="test pass" name="test pass" max_lines=10',qr(test.*?added), "added test pass $function");
$t->is_code('', 200, "passed test pass $function");
$t->ok( 'log "20 test"');
$t->ok( 'log "21 test"');
$t->ok( 'log "22 test"');
$t->ok( 'log "23 test"');
$t->ok( 'log "24 test"');
$t->ok( 'log "25 test"');
$t->ok( 'log "26 test"');
$t->ok( 'log "27 test"');
$t->ok( 'log "28 test"');
$t->ok( 'log "29 test pass"');

$t->like_body( 'test add like="test fail" name="test fail" max_lines=10',qr(test.*?added), "added test fail $function");
$t->is_code('', 417, "failed test fail $function");
$t->ok( 'log "32 test"');
$t->ok( 'log "33 test"');
$t->ok( 'log "34 test"');
$t->ok( 'log "35 test"');
$t->ok( 'log "36 test"');
$t->ok( 'log "37 test"');
$t->ok( 'log "38 test"');
$t->ok( 'log "39 test"');
$t->ok( 'log "40 test"');
$t->ok( 'log "41 test"');
$test_master->done(31, "finish testing $function" );

# Must clear out the line still in the cache from the prior fail.
$t->ok( 'clear lines');



( run in 0.552 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )