ZOMG use strict and warnings in tests
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / explict_versions.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::ExplicitVersions';
12
13 my $versions = [map "$_.0", 0..100];
14
15 {
16   my $vh = ExplicitVersions->new({
17     ordered_versions => $versions,
18     schema_version => '2.0',
19     database_version => '1.0',
20   });
21
22   ok $vh, 'VersionHandler gets instantiated';
23
24   ok(
25     eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
26     'first version pair works'
27   );
28   ok(
29     !$vh->next_version_set,
30     'next version set returns undef when we are done'
31   );
32 }
33
34 {
35   my $vh = ExplicitVersions->new({
36     ordered_versions => $versions,
37     to_version => '1.0',
38     schema_version => '1.0',
39     database_version => '1.0',
40   });
41
42   ok $vh, 'VersionHandler gets instantiated';
43
44   ok(
45     !$vh->next_version_set,
46     'next version set returns undef if we are at the version requested'
47   );
48 }
49
50 {
51   my $vh = ExplicitVersions->new({
52     ordered_versions => $versions,
53     to_version => '5.0',
54     schema_version => '1.0',
55     database_version => '1.0',
56   });
57
58   ok $vh, 'VersionHandler gets instantiated';
59   ok(
60     eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
61     'first version pair works'
62   );
63   ok(
64     eq_array($vh->next_version_set, [qw( 2.0 3.0 )]),
65     'second version pair works'
66   );
67   ok(
68     eq_array($vh->next_version_set, [qw( 3.0 4.0 )]),
69     'third version pair works'
70   );
71   ok(
72     eq_array($vh->next_version_set, [qw( 4.0 5.0 )]),
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 {
80   my $vh = ExplicitVersions->new({
81     ordered_versions => $versions,
82     to_version => '1.0',
83     schema_version => '5.0',
84     database_version => '5.0',
85   });
86
87   ok $vh, 'VersionHandler gets instantiated';
88   ok(
89     eq_array($vh->previous_version_set, [qw( 5.0 4.0 )]),
90     'first version pair works'
91   );
92   ok(
93     eq_array($vh->previous_version_set, [qw( 4.0 3.0 )]),
94     'second version pair works'
95   );
96   ok(
97     eq_array($vh->previous_version_set, [qw( 3.0 2.0 )]),
98     'third version pair works'
99   );
100   ok(
101     eq_array($vh->previous_version_set, [qw( 2.0 1.0 )]),
102     'fourth version pair works'
103   );
104   ok( !$vh->previous_version_set, 'no more versions after final pair' );
105   ok( !$vh->previous_version_set, 'still no more versions after final pair' );
106 }
107
108 dies_ok {
109   my $vh = ExplicitVersions->new({
110     ordered_versions => $versions,
111     schema_version => '2.0',
112     database_version => '1.1',
113   });
114   $vh->next_version_set
115 } 'dies if database version not found in ordered_versions';
116
117 dies_ok {
118   my $vh = ExplicitVersions->new({
119     ordered_versions => $versions,
120     to_version => '0.0',
121     schema_version => '1.0',
122     database_version => '1.0',
123   });
124   $vh->next_version_set;
125 } 'cannot request an upgrade before the current version';
126
127 dies_ok {
128   my $vh = ExplicitVersions->new({
129     ordered_versions => $versions,
130     to_version => '2.0',
131     schema_version => '1.0',
132     database_version => '1.0',
133   });
134   $vh->previous_version_set;
135 } 'cannot request a downgrade after the current version';
136
137 done_testing;
138 #vim: ts=2 sw=2 expandtab