change all the tests to use the new test schema namespace
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / postgresql / basic.t
CommitLineData
41a539b4 1#!/usr/bin/env perl
2
3use warnings;
4use strict;
5use lib 't/lib';
6
7use Test::More;
8use Test::Requires qw(Test::postgresql);
9use Test::Requires qw(POSIX);
10use File::Spec::Functions 'catdir', 'catfile';
11use File::Path 'remove_tree';
12use DBIx::Class::DeploymentHandler;
13use DBICDHTest;
14
15ok my $testdb = build_test_postgresql(),
16 'good test db';
17
18my $dbh = DBI->connect("DBI:Pg:dbname=test;host=127.0.0.1;port=${\$testdb->port}",'postgres','');
19
20VERSION1: {
21 use_ok 'DBICVersion_v1';
60655857 22 $DBICVersion::Schema1::VERSION = 1;
23 ok my $schema = DBICVersion::Schema1->connect(sub { $dbh }),
41a539b4 24 'got schema';
25
26 ok my $dbic_dh = build_dh($schema),
27 'got dbicdh';
28
29 $dbic_dh->prepare_install;
30 make_perl_runfile();
31 $dbic_dh->install;
32
33 is $dbic_dh->database_version, 1, 'correct db version';
34}
35
36VERSION2: {
37 use_ok 'DBICVersion_v2';
60655857 38 $DBICVersion::Schema2::VERSION = 2;
39 ok my $schema = DBICVersion::Schema2->connect(sub { $dbh }),
41a539b4 40 'got schema';
41
42 ok my $dbic_dh = build_dh($schema,1),
43 'got dbicdh';
44
45 $dbic_dh->prepare_install();
46 $dbic_dh->prepare_upgrade();
47 $dbic_dh->prepare_downgrade();
48}
49
50ok -d catdir('t','share','var','pg-deploy','PostgreSQL','downgrade','2-1'),
51 'reasonable defaults properly creates a downgrade';
52
53$testdb->stop(POSIX::SIGINT); ## We need this to stop Pg
54done_testing();
55
56sub build_dh {
57 DBIx::Class::DeploymentHandler->new({
58 script_directory => catdir('t','share','var','pg-deploy'),
59 schema => shift,
60 databases => ['PostgreSQL']});
61}
62
63sub build_test_postgresql {
64 my %config = (
65 base_dir => catdir('t','share','var','pg'),
66 initdb_args => $Test::postgresql::Defaults{initdb_args},
67 postmaster_args => $Test::postgresql::Defaults{postmaster_args});
68
69 if(my $testdb = Test::postgresql->new(%config)) {
70 return $testdb;
71 } else {
72 die $Test::postgresql::errstr;
73 }
74}
75
76sub make_perl_runfile {
77 open(
78 my $perl_run,
79 ">",
80 catfile('t','share','var','pg-deploy','PostgreSQL', 'deploy', '1', '002-test.pl')
60655857 81 ) || do { $testdb->stop(POSIX::SIGINT); die "Cannot open: $!"};
41a539b4 82
83 print $perl_run <<'END';
84 sub {
85 my $schema = shift;
86 };
87END
88
89 close $perl_run;
90}
91
92END {
93 remove_tree catdir('t','share','var','pg');
94 remove_tree catdir('t','share','var','pg-deploy');
95}