c6d0d987a7ea1603586292d5dde3247b66d880f4
[dbsrgits/DBIx-Class-DeploymentHandler.git] / t / version_handlers / explict_versions.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::ExplicitVersions';
9
10 my $versions = [map "$_.0", 0..100];
11
12 {
13   my $vh = ExplicitVersions->new({
14     ordered_versions => $versions,
15     schema_version => '2.0',
16     database_version => '1.0',
17   });
18
19   ok $vh, 'VersionHandler gets instantiated';
20
21   ok(
22     eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
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 = ExplicitVersions->new({
33     ordered_versions => $versions,
34     to_version => '1.0',
35     schema_version => '1.0',
36     database_version => '1.0',
37   });
38
39   ok $vh, 'VersionHandler gets instantiated';
40
41   ok(
42     !$vh->next_version_set,
43     'next version set returns undef if we are at the version requested'
44   );
45 }
46
47 {
48   my $vh = ExplicitVersions->new({
49     ordered_versions => $versions,
50     to_version => '5.0',
51     schema_version => '1.0',
52     database_version => '1.0',
53   });
54
55   ok $vh, 'VersionHandler gets instantiated';
56   ok(
57     eq_array($vh->next_version_set, [qw( 1.0 2.0 )]),
58     'first version pair works'
59   );
60   ok(
61     eq_array($vh->next_version_set, [qw( 2.0 3.0 )]),
62     'second version pair works'
63   );
64   ok(
65     eq_array($vh->next_version_set, [qw( 3.0 4.0 )]),
66     'third version pair works'
67   );
68   ok(
69     eq_array($vh->next_version_set, [qw( 4.0 5.0 )]),
70     'fourth version pair works'
71   );
72   ok( !$vh->next_version_set, 'no more versions after final pair' );
73   ok( !$vh->next_version_set, 'still no more versions after final pair' );
74 }
75
76 dies_ok {
77   my $vh = ExplicitVersions->new({
78     ordered_versions => $versions,
79     schema_version => '1.0',
80     database_version => '1.1',
81   });
82   $vh->next_vesion_set
83 } 'dies if database version not found in ordered_versions';
84
85 dies_ok {
86   my $vh = ExplicitVersions->new({
87     ordered_versions => $versions,
88     to_version => '0.0',
89     schema_version => '1.0',
90     database_version => '1.0',
91   });
92 } 'cannot request a version before the current version';
93
94 done_testing;
95 #vim: ts=2 sw=2 expandtab