dump code now skips+warns instead of dies when dump_overwrite not set [from nilsonsfj]
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 22dump.t
1 use strict;
2 use Test::More;
3 use Test::Warn;
4 use lib qw(t/lib);
5 use File::Path;
6 use make_dbictest_db;
7
8 my $dump_path = './t/_dump';
9
10 {
11     package DBICTest::Schema::1;
12     use base qw/ DBIx::Class::Schema::Loader /;
13     __PACKAGE__->loader_options(
14         relationships => 1,
15         dump_directory => $dump_path,
16     );
17 }
18
19 {
20     package DBICTest::Schema::2;
21     use base qw/ DBIx::Class::Schema::Loader /;
22     __PACKAGE__->loader_options(
23         relationships => 1,
24         dump_directory => $dump_path,
25         dump_overwrite => 1,
26     );
27 }
28
29 plan tests => 4;
30
31 rmtree($dump_path, 1, 0711);
32
33 eval { DBICTest::Schema::1->connect($make_dbictest_db::dsn) };
34 ok(!$@, 'no death with dump_directory set') or diag "Dump failed: $@";
35
36 DBICTest::Schema::1->loader(undef);
37 warnings_like { DBICTest::Schema::1->connect($make_dbictest_db::dsn) }
38     [
39         qr|Dumping manual schema|,
40         (qr|DBICTest/Schema/1.*?.pm exists, will not overwrite|) x 3,
41         qr|Schema dump completed|
42     ],
43     'warn and skip when attempting to overwrite without option';
44
45 rmtree($dump_path, 1, 0711);
46
47 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
48 ok(!$@, 'no death with dump_directory set (overwrite1)')
49     or diag "Dump failed: $@";
50
51 DBICTest::Schema::2->loader(undef);
52 eval { DBICTest::Schema::2->connect($make_dbictest_db::dsn) };
53 ok(!$@, 'no death with dump_directory set (overwrite2)')
54     or diag "Dump failed: $@";
55
56 END { rmtree($dump_path, 1, 1); }