ZOMG use strict and warnings in tests
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / monotonic.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use lib 't/lib';
10 use 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({
33     to_version       => 1,
34     schema_version   => 1,
35     database_version => 1,
36   });
37
38   ok $vh, 'VersionHandler gets instantiated';
39
40   ok(
41     !$vh->next_version_set,
42     'next version set returns undef if we are at the version requested'
43   );
44 }
45
46 ONETOFIVE: {
47   my $vh = Monotonic->new({
48     to_version       => 5,
49     schema_version   => 1,
50     database_version => 1,
51   });
52
53   ok $vh, 'VersionHandler gets instantiated';
54   ok(
55     eq_array($vh->next_version_set, [1,2]),
56     'first version pair works'
57   );
58   ok(
59     eq_array($vh->next_version_set, [2,3]),
60     'second version pair works'
61   );
62   ok(
63     eq_array($vh->next_version_set, [3,4]),
64     'third version pair works'
65   );
66   ok(
67     eq_array($vh->next_version_set, [4,5]),
68     'fourth version pair works'
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
74 FIVETOONE: {
75   my $vh = Monotonic->new({
76     to_version       => 1,
77     schema_version   => 1,
78     database_version => 5,
79   });
80
81   ok $vh, 'VersionHandler gets instantiated';
82   ok(
83     eq_array($vh->previous_version_set, [5,4]),
84     'first version pair works'
85   );
86   ok(
87     eq_array($vh->previous_version_set, [4,3]),
88     'second version pair works'
89   );
90   ok(
91     eq_array($vh->previous_version_set, [3,2]),
92     'third version pair works'
93   );
94   ok(
95     eq_array($vh->previous_version_set, [2,1]),
96     'fourth version pair works'
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
102 dies_ok {
103   my $vh = Monotonic->new({
104     schema_version   => 2,
105     database_version => '1.1',
106   });
107   $vh->next_version_set
108 } 'dies if database version not an Int';
109
110 dies_ok {
111   my $vh = Monotonic->new({
112     to_version       => 0,
113     schema_version   => 1,
114     database_version => 1,
115   });
116   $vh->next_version_set;
117 } 'cannot request an upgrade version before the current version';
118
119 dies_ok {
120   my $vh = Monotonic->new({
121     to_version       => 2,
122     schema_version   => 1,
123     database_version => 1,
124   });
125   $vh->previous_version_set;
126 } 'cannot request a downgrade version after the current version';
127
128 done_testing;
129 #vim: ts=2 sw=2 expandtab