ZOMG use strict and warnings in tests
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / monotonic.t
CommitLineData
dab1797d 1#!perl
2
cbbd1b5f 3use strict;
4use warnings;
5
dab1797d 6use Test::More;
7use Test::Exception;
8
9use lib 't/lib';
10use aliased
11 'DBIx::Class::DeploymentHandler::VersionHandler::Monotonic';
12
13{
14 my $vh = Monotonic->new({
15 schema_version => 2,
16 database_version => 1,
17 });
18
19 ok $vh, 'VersionHandler gets instantiated';
20
21 ok(
22 eq_array($vh->next_version_set, [1,2]),
23 'first version pair works'
24 );
25 ok(
26 !$vh->next_version_set,
27 'next version set returns undef when we are done'
28 );
29}
30
31{
32 my $vh = Monotonic->new({
48c3a562 33 to_version => 1,
34 schema_version => 1,
35 database_version => 1,
dab1797d 36 });
37
38 ok $vh, 'VersionHandler gets instantiated';
39
40 ok(
48c3a562 41 !$vh->next_version_set,
42 'next version set returns undef if we are at the version requested'
dab1797d 43 );
44}
45
4b2aa48a 46ONETOFIVE: {
dab1797d 47 my $vh = Monotonic->new({
48c3a562 48 to_version => 5,
49 schema_version => 1,
50 database_version => 1,
dab1797d 51 });
52
53 ok $vh, 'VersionHandler gets instantiated';
54 ok(
48c3a562 55 eq_array($vh->next_version_set, [1,2]),
56 'first version pair works'
dab1797d 57 );
58 ok(
48c3a562 59 eq_array($vh->next_version_set, [2,3]),
60 'second version pair works'
dab1797d 61 );
62 ok(
48c3a562 63 eq_array($vh->next_version_set, [3,4]),
64 'third version pair works'
dab1797d 65 );
66 ok(
48c3a562 67 eq_array($vh->next_version_set, [4,5]),
68 'fourth version pair works'
dab1797d 69 );
70 ok( !$vh->next_version_set, 'no more versions after final pair' );
71 ok( !$vh->next_version_set, 'still no more versions after final pair' );
72}
73
4b2aa48a 74FIVETOONE: {
75 my $vh = Monotonic->new({
48c3a562 76 to_version => 1,
77 schema_version => 1,
78 database_version => 5,
4b2aa48a 79 });
80
81 ok $vh, 'VersionHandler gets instantiated';
82 ok(
48c3a562 83 eq_array($vh->previous_version_set, [5,4]),
84 'first version pair works'
4b2aa48a 85 );
86 ok(
48c3a562 87 eq_array($vh->previous_version_set, [4,3]),
88 'second version pair works'
4b2aa48a 89 );
90 ok(
48c3a562 91 eq_array($vh->previous_version_set, [3,2]),
92 'third version pair works'
4b2aa48a 93 );
94 ok(
48c3a562 95 eq_array($vh->previous_version_set, [2,1]),
96 'fourth version pair works'
4b2aa48a 97 );
98 ok( !$vh->previous_version_set, 'no more versions before initial pair' );
99 ok( !$vh->previous_version_set, 'still no more versions before initial pair' );
100}
101
dab1797d 102dies_ok {
103 my $vh = Monotonic->new({
48c3a562 104 schema_version => 2,
105 database_version => '1.1',
dab1797d 106 });
df0fcae9 107 $vh->next_version_set
dab1797d 108} 'dies if database version not an Int';
109
110dies_ok {
111 my $vh = Monotonic->new({
48c3a562 112 to_version => 0,
113 schema_version => 1,
114 database_version => 1,
dab1797d 115 });
df0fcae9 116 $vh->next_version_set;
117} 'cannot request an upgrade version before the current version';
118
119dies_ok {
120 my $vh = Monotonic->new({
48c3a562 121 to_version => 2,
122 schema_version => 1,
123 database_version => 1,
df0fcae9 124 });
125 $vh->previous_version_set;
126} 'cannot request a downgrade version after the current version';
dab1797d 127
128done_testing;
129#vim: ts=2 sw=2 expandtab