File: 04_integration_test.t

package info (click to toggle)
libdbix-class-schema-config-perl 0.001011-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 240 kB
  • ctags: 126
  • sloc: perl: 2,019; makefile: 2
file content (100 lines) | stat: -rw-r--r-- 3,641 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl
use warnings;
use strict;
use Test::More;
use lib 't/lib'; # Tests above t/
use lib 'lib';   # Tests inside t/
use DBIx::Class::Schema::Config::Test;

# Using a config file.
my $expected_config = [
    {
        't/etc/config.perl' => {
            'TEST' => {
                'password' => '',
                'dsn' => 'dbi:SQLite:dbname=:memory:',
                'user' => ''
            },
            'PLUGIN' => {
                'password' => '',
                'dsn' => 'dbi:SQLite:dbname=%s',
               'user' => ''
            }
        }
    }
];

is_deeply(DBIx::Class::Schema::Config::Test->config, $expected_config, 
    'config from class accessor matches as expected - loaded before connect');

ok my $Schema1 = DBIx::Class::Schema::Config::Test->connect('TEST'),
    "Can connect to the Test Schema.";

ok $Schema1->storage->dbh->do( "CREATE TABLE hash ( key text, value text )" ),
    "Can create table against the raw dbh.";

ok $Schema1->resultset('Hash')->create( { key => "Dr", value => "Spaceman" } ),
    "Can write to the Test Schema.";

is $Schema1->resultset('Hash')->find( { key => 'Dr' }, { key => 'key_unique' } )->value, 'Spaceman',
    "Can read from the Test Schema.";

# Pass through of array.
ok my $Schema2 = DBIx::Class::Schema::Config::Test->connect('dbi:SQLite:dbname=:memory:', '', ''),
    "Can connect to the Test Schema.";

ok $Schema2->storage->dbh->do( "CREATE TABLE hash ( key text, value text )" ),
    "Can create table against the raw dbh.";

ok $Schema2->resultset('Hash')->create( { key => "Dr", value => "Spaceman" } ),
    "Can write to the Test Schema.";

is $Schema2->resultset('Hash')->find( { key => 'Dr' }, { key => 'key_unique' } )->value, 'Spaceman',
    "Can read from the Test Schema.";
    
# Pass through of hash
ok my $Schema3 = DBIx::Class::Schema::Config::Test->connect({ dsn => 'dbi:SQLite:dbname=:memory:' }),
    "Can connect to the Test Schema.";

ok $Schema3->storage->dbh->do( "CREATE TABLE hash ( key text, value text )" ),
    "Can create table against the raw dbh.";

ok $Schema3->resultset('Hash')->create( { key => "Dr", value => "Spaceman" } ),
    "Can write to the Test Schema.";

is $Schema3->resultset('Hash')->find( { key => 'Dr' }, { key => 'key_unique' } )->value, 'Spaceman',
    "Can read from the Test Schema.";
    
    
# Pass through of code reference.
ok my $Schema4 = DBIx::Class::Schema::Config::Test->connect(
        sub { DBI->connect( 'dbi:SQLite:dbname=:memory:', undef, undef, { RaiseError => 1 } ) } 
    ), "Can connect to the Test Schema.";

ok $Schema4->storage->dbh->do( "CREATE TABLE hash ( key text, value text )" ),
    "Can create table against the raw dbh.";

ok $Schema4->resultset('Hash')->create( { key => "Dr", value => "Spaceman" } ),
    "Can write to the Test Schema.";

is $Schema4->resultset('Hash')->find( { key => 'Dr' }, { key => 'key_unique' } )->value, 'Spaceman',
    "Can read from the Test Schema.";
    
# dbh_maker functions as one would expect.
ok my $Schema5 = DBIx::Class::Schema::Config::Test->connect({
        dbh_maker => sub {
            DBI->connect( 'dbi:SQLite:dbname=:memory:', undef, undef, { RaiseError => 1 } )
        }, 
    }), "Can connect to the Test Schema.";

ok $Schema5->storage->dbh->do( "CREATE TABLE hash ( key text, value text )" ),
    "Can create table against the raw dbh.";

ok $Schema5->resultset('Hash')->create( { key => "Dr", value => "Spaceman" } ),
    "Can write to the Test Schema.";

is $Schema5->resultset('Hash')->find( { key => 'Dr' }, { key => 'key_unique' } )->value, 'Spaceman',
    "Can read from the Test Schema.";
    
    
done_testing;