monotonic (and others) now pass
[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 ONETOFIVE: {
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 FIVETOONE: {
72   my $vh = Monotonic->new({
73     to_version       => 1,
74     schema_version   => 1,
75     database_version => 5,
76   });
77
78   ok $vh, 'VersionHandler gets instantiated';
79   ok(
80     eq_array($vh->previous_version_set, [5,4]),
81     'first version pair works'
82   );
83   ok(
84     eq_array($vh->previous_version_set, [4,3]),
85     'second version pair works'
86   );
87   ok(
88     eq_array($vh->previous_version_set, [3,2]),
89     'third version pair works'
90   );
91   ok(
92     eq_array($vh->previous_version_set, [2,1]),
93     'fourth version pair works'
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
99 dies_ok {
100   my $vh = Monotonic->new({
101     schema_version   => 2,
102     database_version => '1.1',
103   });
104   $vh->next_version_set
105 } 'dies if database version not an Int';
106
107 dies_ok {
108   my $vh = Monotonic->new({
109     to_version       => 0,
110     schema_version   => 1,
111     database_version => 1,
112   });
113   $vh->next_version_set;
114 } 'cannot request an upgrade version before the current version';
115
116 dies_ok {
117   my $vh = Monotonic->new({
118     to_version       => 2,
119     schema_version   => 1,
120     database_version => 1,
121   });
122   $vh->previous_version_set;
123 } 'cannot request a downgrade version after the current version';
124
125 done_testing;
126 #vim: ts=2 sw=2 expandtab