use VersionStorage in the rest of our stuff
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / 03_explict_versions.t
CommitLineData
2c627d9e 1#!perl
2
3use Test::More;
4use Test::Exception;
5
6use lib 't/lib';
7use DBICTest;
8use DBIx::Class::DeploymentHandler;
c703d15d 9use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
2c627d9e 10my $db = 'dbi:SQLite:db.db';
11my @connection = ($db, '', '', { ignore_version => 1 });
12my $sql_dir = 't/sql';
13
14unlink 'db.db' if -e 'db.db';
15if (-d 't/sql') {
16 unlink $_ for glob('t/sql/*');
17} else {
18 mkdir 't/sql';
19}
20
21use DBICVersion_v1;
22my $s = DBICVersion::Schema->connect(@connection);
23
24my $handler = DBIx::Class::DeploymentHandler->new({
25 upgrade_directory => $sql_dir,
26 schema => $s,
27 databases => 'SQLite',
fb105cfa 28 sqltargs => { add_drop_table => 0 },
2c627d9e 29});
30
fb105cfa 31my $v_storage = $handler->version_storage;
32
2c627d9e 33my $version = $s->schema_version();
a912450b 34$handler->prepare_install();
2c627d9e 35
36$handler->install;
37
38my $versions = [map "$_.0", 0..100];
39
40{
c703d15d 41 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
2c627d9e 42 schema => $s,
43 ordered_versions => $versions,
44 to_version => '1.0',
fb105cfa 45 version_storage => $v_storage,
2c627d9e 46 });
47
48 ok $vh, 'VersionHandler gets instantiated';
49
50 ok( !$vh->next_version_set, 'next version set returns undef if we are at the version requested' );
51}
52
53{
c703d15d 54 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
2c627d9e 55 schema => $s,
56 ordered_versions => $versions,
57 to_version => '5.0',
fb105cfa 58 version_storage => $v_storage,
2c627d9e 59 });
60
61 ok $vh, 'VersionHandler gets instantiated';
62 ok( eq_array($vh->next_version_set, [qw( 1.0 2.0 )]), 'first version pair works' );
63 ok( eq_array($vh->next_version_set, [qw( 2.0 3.0 )]), 'second version pair works' );
64 ok( eq_array($vh->next_version_set, [qw( 3.0 4.0 )]), 'third version pair works' );
65 ok( eq_array($vh->next_version_set, [qw( 4.0 5.0 )]), 'fourth version pair works' );
66 ok( !$vh->next_version_set, 'no more versions after final pair' );
67 ok( !$vh->next_version_set, 'still no more versions after final pair' );
68}
69
70dies_ok {
c703d15d 71 my $vh = DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new({
2c627d9e 72 schema => $s,
73 ordered_versions => $versions,
74 to_version => '0.0',
fb105cfa 75 version_storage => $v_storage,
2c627d9e 76 });
77} 'cannot request a version before the current version';
78
79done_testing;
80__END__
81
82vim: ts=2 sw=2 expandtab