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