fix IDENTITY data_type for Sybase, more extra tests for Sybase
[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
6 my $dsn      = $ENV{DBICTEST_SYBASE_DSN} || '';
7 my $user     = $ENV{DBICTEST_SYBASE_USER} || '';
8 my $password = $ENV{DBICTEST_SYBASE_PASS} || '';
9
10 my $tester = dbixcsl_common_tests->new(
11     vendor      => 'sybase',
12     auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
13     dsn         => $dsn,
14     user        => $user,
15     password    => $password,
16     extra       => {
17         create  => [
18             q{
19                 CREATE TABLE sybase_loader_test1 (
20                     id INTEGER IDENTITY NOT NULL PRIMARY KEY,
21                     ts timestamp,
22                     charfield VARCHAR(10) DEFAULT 'foo',
23                     computed_dt AS getdate()
24                 )
25             },
26         ],
27         drop  => [ qw/ sybase_loader_test1 / ],
28         count => 7,
29         run   => sub {
30             my ($schema, $monikers, $classes) = @_;
31
32             my $rs = $schema->resultset($monikers->{sybase_loader_test1});
33             my $rsrc = $rs->result_source;
34
35             is $rsrc->column_info('id')->{data_type},
36                 'numeric',
37                 'INTEGER IDENTITY data_type is correct';
38
39             is $rsrc->column_info('id')->{is_auto_increment},
40                 1,
41                 'INTEGER IDENTITY is_auto_increment => 1';
42
43             {
44                 local $TODO = 'timestamp introspection broken';
45
46                 is $rsrc->column_info('ts')->{data_type},
47                    'timestamp',
48                    'timestamps have the correct data_type';
49             }
50
51             is $rsrc->column_info('charfield')->{data_type},
52                 'varchar',
53                 'VARCHAR has correct data_type';
54
55             {
56                 local $TODO = 'constant DEFAULT introspection';
57
58                 is $rsrc->column_info('charfield')->{default},
59                     'foo',
60                     'constant DEFAULT is correct';
61             }
62
63             is $rsrc->column_info('charfield')->{size},
64                 10,
65                 'VARCHAR(10) has correct size';
66
67             {
68                 local $TODO = 'data_type for computed columns';
69
70                 ok ((exists $rsrc->column_info('computed_dt')->{data_type}
71                   && (not defined $rsrc->column_info('computed_dt')->{data_type})),
72                     'data_type for computed column exists and is undef')
73 #               or diag "Data type is: ",
74 #                   $rsrc->column_info('computed_dt')->{data_type}
75                 ;
76             }
77         },
78     },
79 );
80
81 if( !$dsn || !$user ) {
82     $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables');
83 }
84 else {
85     $tester->run_tests();
86 }