903592f6ba54c5552f68f4c5145054c0badd0938
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 15sybase_common.t
1 use strict;
2 use lib qw(t/lib);
3 use dbixcsl_common_tests;
4 use Test::More;
5 use Test::Exception;
6
7 my $dsn      = $ENV{DBICTEST_SYBASE_DSN} || '';
8 my $user     = $ENV{DBICTEST_SYBASE_USER} || '';
9 my $password = $ENV{DBICTEST_SYBASE_PASS} || '';
10
11 my $tester = dbixcsl_common_tests->new(
12     vendor      => 'sybase',
13     auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
14     dsn         => $dsn,
15     user        => $user,
16     password    => $password,
17     extra       => {
18         create  => [
19             q{
20                 CREATE TABLE sybase_loader_test1 (
21                     id INTEGER IDENTITY NOT NULL PRIMARY KEY,
22                     ts timestamp,
23                     charfield VARCHAR(10) DEFAULT 'foo',
24                     computed_dt AS getdate()
25                 )
26             },
27         ],
28         drop  => [ qw/ sybase_loader_test1 / ],
29         count => 9,
30         run   => sub {
31             my ($schema, $monikers, $classes) = @_;
32
33             my $rs = $schema->resultset($monikers->{sybase_loader_test1});
34             my $rsrc = $rs->result_source;
35
36             is $rsrc->column_info('id')->{data_type},
37                 'numeric',
38                 'INTEGER IDENTITY data_type is correct';
39
40             is $rsrc->column_info('id')->{is_auto_increment},
41                 1,
42                 'INTEGER IDENTITY is_auto_increment => 1';
43
44             {
45                 local $TODO = 'timestamp introspection broken';
46
47                 is $rsrc->column_info('ts')->{data_type},
48                    'timestamp',
49                    'timestamps have the correct data_type';
50             }
51
52             is $rsrc->column_info('charfield')->{data_type},
53                 'varchar',
54                 'VARCHAR has correct data_type';
55
56             {
57                 local $TODO = 'constant DEFAULT introspection';
58
59                 is $rsrc->column_info('charfield')->{default_value},
60                     'foo',
61                     'constant DEFAULT is correct';
62             }
63
64             is $rsrc->column_info('charfield')->{size},
65                 10,
66                 'VARCHAR(10) has correct size';
67
68             ok ((exists $rsrc->column_info('computed_dt')->{data_type}
69               && (not defined $rsrc->column_info('computed_dt')->{data_type})),
70                 'data_type for computed column exists and is undef')
71             or diag "Data type is: ",
72                 $rsrc->column_info('computed_dt')->{data_type}
73             ;
74
75             {
76                 local $TODO = 'default_value for computed columns';
77
78                 my $computed_dt_default =
79                     $rsrc->column_info('computed_dt')->{default_value};
80
81                 ok ((ref $computed_dt_default eq 'SCALAR'),
82                     'default_value for computed column is a scalar ref')
83 #                or diag "default_value is: ", $computed_dt_default
84                 ;
85
86                 eval { is $$computed_dt_default,
87                     'getdate()',
88                     'default_value for computed column is correct' };
89             }
90         },
91     },
92 );
93
94 if( !$dsn || !$user ) {
95     $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables');
96 }
97 else {
98     $tester->run_tests();
99 }