Delete basicrels tests. Modify run tests to use new syntax. Remove helperrels test...
[dbsrgits/DBIx-Class.git] / t / run / 12pg.tl
CommitLineData
70350518 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
0567538f 8my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
9
10#warn "$dsn $user $pass";
11
70350518 12plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
b6b65a3e 13 . ' (note: creates and drops a table named artist!)' unless ($dsn && $user);
0567538f 14
fc22fbac 15plan tests => 4;
0567538f 16
70fe6d6e 17DBICTest::Schema->compose_connection('PgTest' => $dsn, $user, $pass);
0567538f 18
a953d8d9 19my $dbh = PgTest->schema->storage->dbh;
4d272ce5 20PgTest->schema->source("Artist")->name("testschema.artist");
21$dbh->do("CREATE SCHEMA testschema;");
22$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
0567538f 23
843f8ecd 24PgTest::Artist->load_components('PK::Auto');
0567538f 25
26my $new = PgTest::Artist->create({ name => 'foo' });
27
b6b65a3e 28is($new->artistid, 1, "Auto-PK worked");
29
30$new = PgTest::Artist->create({ name => 'bar' });
31
32is($new->artistid, 2, "Auto-PK worked");
33
a953d8d9 34my $test_type_info = {
35 'artistid' => {
103e3e03 36 'data_type' => 'integer',
37 'is_nullable' => 0,
fc22fbac 38 'size' => 4,
a953d8d9 39 },
40 'name' => {
103e3e03 41 'data_type' => 'character varying',
42 'is_nullable' => 1,
fc22fbac 43 'size' => 255,
44 'default_value' => undef,
103e3e03 45 },
46 'charfield' => {
47 'data_type' => 'character',
a953d8d9 48 'is_nullable' => 1,
fc22fbac 49 'size' => 10,
50 'default_value' => undef,
103e3e03 51 },
a953d8d9 52};
53
fc22fbac 54
4d272ce5 55my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
fc22fbac 56my $artistid_defval = delete $type_info->{artistid}->{default_value};
57like($artistid_defval,
4d272ce5 58 qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
fc22fbac 59 'columns_info_for - sequence matches Pg get_autoinc_seq expectations');
60is_deeply($type_info, $test_type_info,
61 'columns_info_for - column data types');
a953d8d9 62
4d272ce5 63$dbh->do("DROP TABLE testschema.artist;");
64$dbh->do("DROP SCHEMA testschema;");
0567538f 65