Change to using memory sqlite db and schema based populating

This commit is contained in:
Tom Bloor 2017-04-18 13:14:35 +01:00
parent e932c60af3
commit 6f544b1209

View file

@ -1,39 +1,43 @@
use Mojo::Base -strict; use Mojo::Base -strict;
use File::Temp;
use Test::More; use Test::More;
use Test::Mojo; use Test::Mojo;
use Mojo::JSON; use Mojo::JSON;
use FindBin; my $file = File::Temp->new;
BEGIN { print $file <<'END';
$ENV{MOJO_MODE} = 'testing'; {
$ENV{MOJO_LOG_LEVEL} = 'debug'; dsn => "dbi:SQLite::memory:",
user => undef,
pass => undef,
} }
END
$file->seek( 0, SEEK_END );
my $t = Test::Mojo->new("Pear::LocalLoop"); $ENV{MOJO_CONFIG} = $file->filename;
my $dbh = $t->app->db; my $t = Test::Mojo->new('Pear::LocalLoop');
my $schema = $t->app->schema;
$schema->deploy;
#Dump all pf the test tables and start again. $schema->resultset('AgeRange')->populate([
my $sqlDeployment = Mojo::File->new("$FindBin::Bin/../dropschema.sql")->slurp; [ qw/ agerangestring / ],
for (split ';', $sqlDeployment){ [ '20-35' ],
$dbh->do($_) or die $dbh->errstr; [ '35-50' ],
} [ '50+' ],
]);
$sqlDeployment = Mojo::File->new("$FindBin::Bin/../schema.sql")->slurp;
for (split ';', $sqlDeployment){
$dbh->do($_) or die $dbh->errstr;
}
#Variables to be used for uniqueness when testing. #Variables to be used for uniqueness when testing.
my @names = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); my @names = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
my @emails = ('a@a.com', 'b@a.com', 'c@a.com', 'd@a.com', 'e@a.com', 'f@a.com', 'g@a.com', 'h@a.com', 'i@a.com', 'j@a.com', 'k@a.com', 'l@a.com', 'm@a.com', 'n@a.com', 'o@a.com', 'p@a.com', 'q@a.com', 'r@a.com', 's@a.com', 't@a.com', 'u@a.com', 'v@a.com', 'w@a.com', 'x@a.com', 'y@a.com', 'z@a.com'); my @emails = ('a@a.com', 'b@a.com', 'c@a.com', 'd@a.com', 'e@a.com', 'f@a.com', 'g@a.com', 'h@a.com', 'i@a.com', 'j@a.com', 'k@a.com', 'l@a.com', 'm@a.com', 'n@a.com', 'o@a.com', 'p@a.com', 'q@a.com', 'r@a.com', 's@a.com', 't@a.com', 'u@a.com', 'v@a.com', 'w@a.com', 'x@a.com', 'y@a.com', 'z@a.com');
my @tokens = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); my @tokens = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
my $tokenStatement = $dbh->prepare('INSERT INTO AccountTokens (AccountTokenName) VALUES (?)');
foreach (@tokens){ $schema->resultset('AccountToken')->populate([
my $rowsAdded = $tokenStatement->execute($_); [ qw/ accounttokenname / ],
} map { [ $_ ] } @tokens,
]);
#No JSON sent #No JSON sent
$t->post_ok('/api/register') $t->post_ok('/api/register')