-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from waterkip/act-psgi-act-config-test
Add test DB for testing on docker
- Loading branch information
Showing
31 changed files
with
157 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
\c act | ||
|
||
INSERT INTO schema (current_version) VALUES (12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
CREATE database act_test WITH TEMPLATE act; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,46 @@ | ||
use warnings; | ||
use strict; | ||
use Act::Config; | ||
use DBI; | ||
use Test::More tests => 16; | ||
|
||
my @databases = ( | ||
[ 'main', | ||
$Config->database_dsn, | ||
$Config->database_user, | ||
$Config->database_passwd, | ||
], | ||
[ 'test', | ||
$Config->database_test_dsn, | ||
$Config->database_test_user, | ||
$Config->database_test_passwd, | ||
], | ||
[ 'wiki', | ||
'dbi:Pg:dbname=' . $Config->wiki_dbname, | ||
$Config->wiki_dbuser, | ||
$Config->wiki_dbpass, | ||
], | ||
); | ||
use Test::More; | ||
use Test::Deep; | ||
use Test::Exception; | ||
|
||
use Test::MockObject; | ||
|
||
require_ok('Act::Database'); | ||
for my $d (@databases) { | ||
my ($name, @c) = @$d; | ||
my $is_pg = $c[0] =~ /Pg:/ ? 1 : 0; | ||
|
||
my $dbh = DBI->connect(@c, | ||
{ AutoCommit => 0, | ||
PrintError => 0, | ||
pg_enable_utf8 => 1, | ||
} | ||
); | ||
|
||
if (not ok $dbh, "$name connect") { | ||
SKIP: { | ||
skip "connect failed; following tests can't be run", 4 | ||
} | ||
next | ||
} | ||
|
||
SKIP: { | ||
skip "tests specific to PostgreSQL", 2 unless $is_pg; | ||
cmp_ok($dbh->{pg_server_version}, '>=', 80000, "$name server version"); | ||
cmp_ok($dbh->{pg_lib_version}, '>=', 80000, "$name library version"); | ||
} | ||
|
||
SKIP: { | ||
skip "irrelevent", 1 if $name eq 'wiki'; | ||
my ($version, $required) = Act::Database::get_versions($dbh); | ||
is ($version, $required, "$name schema is up to date"); | ||
} | ||
|
||
eval { $dbh->disconnect }; | ||
is $@, "", "$name disconnect"; | ||
|
||
my $required_version = Act::Database::required_version(); | ||
is($required_version, 12, "12 db upgrades found"); | ||
|
||
{ | ||
my $warn; | ||
local $SIG{__WARN__} = sub { $warn = shift }; | ||
my $dbh = Test::MockObject->new(); | ||
$dbh->mock('selectrow_array' => sub { return undef }); | ||
my @found = Act::Database::get_versions($dbh); | ||
cmp_deeply(\@found, [0, $required_version], "undef returns 0 as a version"); | ||
is($warn, "No database schema version found.\n", ".. and correct warning found"); | ||
} | ||
|
||
{ | ||
my $dbh = Test::MockObject->new(); | ||
$dbh->mock('selectrow_array' => sub { return 12 }); | ||
my @found = Act::Database::get_versions($dbh); | ||
cmp_deeply(\@found, [12, $required_version], "12 returns 12"); | ||
} | ||
|
||
{ | ||
my $dbh = Test::MockObject->new(); | ||
$dbh->mock('selectrow_array' => sub { die "Failure" }); | ||
$dbh->mock('rollback' => sub { 1 }); | ||
$dbh->mock('errstr' => sub { return "we dead" }); | ||
throws_ok( | ||
sub { | ||
Act::Database::get_versions($dbh); | ||
}, | ||
qr/Failed to retrieve the schema version/ | ||
); | ||
} | ||
|
||
done_testing; | ||
|
||
__END__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.