App-Basis-Queue
view release on metacpan or search on metacpan
t/03_simple.t view on Meta::CPAN
#!/usr/bin/perl -w
=head1 NAME
03_simple.t
=head1 DESCRIPTION
perform basic tests on App::Basis::Queue
while the tests are setup into subtests, they are not independent of the
preceding tests as the data the preceding tests creates is used in
subsequent ones
=head1 AUTHOR
kevin mulholland, moodfarm@cpan.org
=cut
use 5.10.0 ;
use feature 'state' ;
use strict ;
use warnings ;
use Test::More ;
use POSIX qw(strftime) ;
use DBI ;
use Try::Tiny ;
use Time::HiRes qw(gettimeofday tv_interval ) ;
BEGIN {
if ( $ENV{AUTHOR_TESTING} ) {
plan tests => 7 ;
} else {
plan tests => 1 ;
}
use_ok('App::Basis::Queue') ;
}
# create a name for the queue we will be testing with, it should not exist!
my $test_q = strftime( "%Y-%m-%d %H:%M:%S", localtime() ) . "_" . $$ . '_' ;
$test_q =~ s/[ :-]/_/g ;
$test_q = 'tst' ;
my $qname = '/basic_q' ;
my $queue_two = "$qname/two" ;
my $queue_three = "$qname/three" ;
my ( $queue, $dbh ) ;
my $add_items = 1000 ;
# get optional DSN info from the user environment
my $dsn
= $ENV{SQ_DSN}
? $ENV{SQ_DSN}
: "dbi:SQLite:/tmp/queue_simple-tasks.$test_q.sqlite3" ;
my $user = $ENV{SQ_USER} ;
my $passwd = $ENV{SQ_PASSWD} ;
# ----------------------------------------------------------------------------
=item query_db
general purpose db query tool, returns all results as a arrayref of hashes
this function was created by kevin outside of home
copyright is retained with him
returns ref to data and a status msg
=cut
sub query_db
{
my ( $dbh, $query, $p ) = @_ ;
our @params = $p ? @$p : () ;
my ( $result, $err, $sth ) ;
try {
$sth = $dbh->prepare($query) ;
my $rv = $sth->execute(@params) ;
# so as to get an array of hashes
$result = $sth->fetchall_arrayref( {} ) ;
}
catch {} ;
return $result, $err ;
}
# ----------------------------------------------------------------------------
# Testing starts here
( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )