initial monotonic commit
[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->previous_version_set, [1,2]),
57          'doing previous version works'
58   );
59   ok(
60          eq_array($vh->next_version_set, [1,2]),
61          'first version pair works again'
62   );
63   ok(
64          eq_array($vh->next_version_set, [2,3]),
65          'second version pair works'
66   );
67   ok(
68          eq_array($vh->next_version_set, [3,4]),
69          'third version pair works'
70   );
71   ok(
72          eq_array($vh->next_version_set, [4,5]),
73          'fourth version pair works'
74   );
75   ok( !$vh->next_version_set, 'no more versions after final pair' );
76   ok( !$vh->next_version_set, 'still no more versions after final pair' );
77 }
78
79 dies_ok {
80   my $vh = Monotonic->new({
81          schema_version   => 2,
82          database_version => '1.1',
83   });
84   $vh->next_vesion_set
85 } 'dies if database version not an Int';
86
87 dies_ok {
88   my $vh = Monotonic->new({
89          to_version       => 0,
90          schema_version   => 1,
91          database_version => 1,
92   });
93 } 'cannot request a version before the current version';
94
95 done_testing;
96 #vim: ts=2 sw=2 expandtab