Removed execution flag from non-exe files
[Fumo.git] / t / 01-import.t
blob56236649d53c20f16544e2b45b2764833f609819
1 use Test::More tests => 7;
2 use Test::Exception;
4 use strict;
5 use warnings;
7 use YAML;
8 use Fumo::Import;
9 use Data::Dumper;
11 use Cwd qw(realpath);
12 use File::Basename;
14 BEGIN { use_ok 'Fumo::Schema' }
16 SKIP: {
17     skip('FUMO_TEST_DSN environment variable not set', 3)
18         unless $ENV{FUMO_TEST_DSN};
20     # the files
21     my $file_map = {
22         'one_file_all_combos_valid.yml' => {
23             name     => 'one file, all combos, valid',
24             throws   => undef,
25             revision => 'Revision1',
26         },
27         'one_file_skip_todo.yml' => {
28             name     => 'one file, todos and skips, valid',
29             throws   => undef,
30             revision => 'Revision2',
31         },
32         'one_file_invalid.yml' => {
33             name     => 'one file, invalid (extra data)',
34             throws   => 'forbidden field: thisisinvalid',
35             revision => 'Revision3',
36         },
37         'many_files_same_tests.yml' => {
38             name     => 'many files, same tests',
39             throws   => undef,
40             revision => 'Revision3',
41         }
42     };
44     # grab the schema
45     my $schema = Fumo::Schema->connect($ENV{FUMO_TEST_DSN});
46     isa_ok($schema, 'Fumo::Schema');
48     # clear the database
49     my $projects_rs = $schema->resultset('Project');
50     $projects_rs->delete_all();
51     cmp_ok($projects_rs->count(), '==', 0,
52            'There are no projects in the database');
54     my $importer = Fumo::Import->new();
56     my $fixture_path = dirname(realpath($0)) . '/01-fixtures/';
57     for my $file (keys %{ $file_map }) {
58         my $details = YAML::LoadFile($fixture_path . $file);
60         # the actual import
61         my $import = sub {
62             $importer->do_import($details, $schema,
63                 'Project1', 'Branch1', $file_map->{$file}->{revision})
64         };
65         
66         # check it lives or throws as it should
67         if ($file_map->{$file}->{throws}) {
68             throws_ok { $import->() } qr/$file_map->{$file}->{throws}/,
69                 "'$file' throws ok";
70         }
71         else {
72             lives_ok { $import->() }
73                 "'$file' imports ok" or diag($file_map->{$file}->{name});
74         }
75     }