33cdfa85a1785c2005f2626ce86ed77b4309b49f
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / monotonic.t
1 #!perl
2
3 use Test::More;
4 use Test::Exception;
5
6 use lib 't/lib';
7 use 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({
30          to_version       => 1,
31          schema_version   => 1,
32          database_version => 1,
33   });
34
35   ok $vh, 'VersionHandler gets instantiated';
36
37   ok(
38          !$vh->next_version_set,
39          'next version set returns undef if we are at the version requested'
40   );
41 }
42
43 {
44   my $vh = Monotonic->new({
45          to_version       => 5,
46          schema_version   => 1,
47          database_version => 1,
48   });
49
50   ok $vh, 'VersionHandler gets instantiated';
51   ok(
52          eq_array($vh->next_version_set, [1,2]),
53          'first version pair works'
54   );
55   ok(
56          eq_array($vh->next_version_set, [2,3]),
57          'second version pair works'
58   );
59   ok(
60          eq_array($vh->next_version_set, [3,4]),
61          'third version pair works'
62   );
63   ok(
64          eq_array($vh->next_version_set, [4,5]),
65          'fourth version pair works'
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
71 dies_ok {
72   my $vh = Monotonic->new({
73          schema_version   => 2,
74          database_version => '1.1',
75   });
76   $vh->next_version_set
77 } 'dies if database version not an Int';
78
79 dies_ok {
80   my $vh = Monotonic->new({
81          to_version       => 0,
82          schema_version   => 1,
83          database_version => 1,
84   });
85   $vh->next_version_set;
86 } 'cannot request an upgrade version before the current version';
87
88 dies_ok {
89   my $vh = Monotonic->new({
90          to_version       => 2,
91          schema_version   => 1,
92          database_version => 1,
93   });
94   $vh->previous_version_set;
95 } 'cannot request a downgrade version after the current version';
96
97 done_testing;
98 #vim: ts=2 sw=2 expandtab