~ubuntu-branches/debian/sid/libpgobject-perl/sid

« back to all changes in this revision

Viewing changes to t/01-basic_dbtests.t

  • Committer: Package Import Robot
  • Author(s): Robert James Clay
  • Date: 2014-04-14 12:56:51 UTC
  • Revision ID: package-import@ubuntu.com-20140414125651-8oislluh4ykxqevw
Tags: upstream-1.400.1
ImportĀ upstreamĀ versionĀ 1.400.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use Test::More;
 
2
use DBI;
 
3
use PGObject;
 
4
 
 
5
plan skip_all => 'Not set up for db tests' unless $ENV{DB_TESTING};
 
6
# Initial setup
 
7
my $dbh1 = DBI->connect('dbi:Pg:', 'postgres') ;
 
8
 
 
9
plan skip_all => 'Needs superuser connection for this test script' unless $dbh1;
 
10
 
 
11
plan tests => 34;
 
12
 
 
13
 
 
14
$dbh1->do('CREATE DATABASE pgobject_test_db');
 
15
 
 
16
 
 
17
my $dbh = DBI->connect('dbi:Pg:dbname=pgobject_test_db', 'postgres');
 
18
$dbh->{pg_server_prepare} = 0;
 
19
 
 
20
# Function to test.
 
21
$dbh->do('
 
22
   CREATE FUNCTION public.pg_object_test
 
23
          (in_test1 int, in_test2 text, in_test3 date)
 
24
   RETURNS BOOL LANGUAGE SQL AS $$ SELECT TRUE $$
 
25
');
 
26
 
 
27
$dbh->do('CREATE DOMAIN public.posint AS int');
 
28
$dbh->do('
 
29
   CREATE FUNCTION public.pg_object_test2
 
30
          (in_test1 posint, in_test2 text, in_test3 date)
 
31
   RETURNS BOOL LANGUAGE SQL AS $$ SELECT TRUE $$
 
32
');
 
33
 
 
34
 
 
35
 
 
36
 
 
37
# Testing function_info()
 
38
my $function_info = PGObject->function_info(
 
39
    dbh      => $dbh,
 
40
    funcname => 'pg_object_test'
 
41
);
 
42
my $function_info2 = PGObject->function_info(
 
43
    dbh        => $dbh,
 
44
    funcname   => 'pg_object_test',
 
45
    funcschema => 'public',
 
46
);
 
47
my $function_info3 = PGObject->function_info(
 
48
    dbh        => $dbh,
 
49
    funcname   => 'pg_object_test',
 
50
    funcschema => 'public',
 
51
    argtype1   => 'int4',
 
52
    argschema  => 'pg_catalog',
 
53
);
 
54
 
 
55
 
 
56
ok(defined $function_info, 'Got function info with default schema');
 
57
ok(defined $function_info2, 'Got function info with specified schema');
 
58
ok(defined $function_info3, 'Got function info with specified schema, first arg type');
 
59
is($function_info->{args}->[0]->{name}, 'in_test1', 
 
60
  'default schema, arg1 name');
 
61
is($function_info->{args}->[1]->{name}, 'in_test2', 
 
62
  'default schema, arg2 name');
 
63
is($function_info->{args}->[2]->{name}, 'in_test3', 
 
64
  'default schema, arg3 name');
 
65
is($function_info2->{args}->[0]->{name}, 'in_test1', 
 
66
  'specified schema, arg1 name');
 
67
is($function_info2->{args}->[1]->{name}, 'in_test2', 
 
68
  'specified schema, arg2 name');
 
69
is($function_info2->{args}->[2]->{name}, 'in_test3', 
 
70
  'specified schema, arg1 name');
 
71
is($function_info3->{args}->[0]->{name}, 'in_test1', 
 
72
  'specified schema and arg type, arg1 name');
 
73
is($function_info3->{args}->[1]->{name}, 'in_test2', 
 
74
  'specified schema and arg type, arg2 name');
 
75
is($function_info3->{args}->[2]->{name}, 'in_test3', 
 
76
  'specified schema and arg type, arg1 name');
 
77
 
 
78
is($function_info->{args}->[0]->{type}, 'integer', 
 
79
  'default schema, arg1 type');
 
80
is($function_info->{args}->[1]->{type}, 'text', 
 
81
  'default schema, arg2 type');
 
82
is($function_info->{args}->[2]->{type}, 'date', 
 
83
  'default schema, arg3 type');
 
84
is($function_info2->{args}->[0]->{type}, 'integer', 
 
85
  'specified schema, arg1 type');
 
86
is($function_info2->{args}->[1]->{type}, 'text', 
 
87
  'specified schema, arg2 type');
 
88
is($function_info2->{args}->[2]->{type}, 'date', 
 
89
  'specified schema, arg1 type');
 
90
is($function_info3->{args}->[0]->{type}, 'integer', 
 
91
  'specified schema/arg type, arg1 type');
 
92
is($function_info3->{args}->[1]->{type}, 'text', 
 
93
  'specified schema/arg type, arg2 type');
 
94
is($function_info3->{args}->[2]->{type}, 'date', 
 
95
  'specified schema/arg type, arg1 type');
 
96
 
 
97
is($function_info->{num_args}, 3, 'Number of args, default schema');
 
98
is($function_info2->{num_args}, 3, 'Number of args, specified schema');
 
99
is($function_info->{name}, 'pg_object_test', 'Func. Name, default schema');
 
100
is($function_info2->{name}, 'pg_object_test', 'Func name, specified schema');
 
101
 
 
102
# Testing call_procedure()
 
103
 
 
104
my ($result1) = PGObject->call_procedure(
 
105
   funcname   => 'pg_object_test',
 
106
   args       => [1, 'test', '2001-01-01'],
 
107
   dbh        => $dbh,
 
108
);
 
109
my ($result2) = PGObject->call_procedure(
 
110
   funcname   => 'pg_object_test',
 
111
   funcschema => 'public',
 
112
   args       => [1, 'test', '2001-01-01'],
 
113
   dbh        => $dbh,
 
114
);
 
115
my ($result3) = PGObject->call_procedure(
 
116
   funcname      => 'pg_object_test',
 
117
   args          => [1, 'test', '2001-01-01'],
 
118
   dbh           => $dbh,
 
119
   running_funcs => [{agg => 'count(*)', alias => 'lines'}]
 
120
);
 
121
my ($result4) = PGObject->call_procedure(
 
122
   funcname   => 'test',
 
123
   funcprefix => 'pg_object_',
 
124
   args       => [1, 'test', '2001-01-01'],
 
125
   dbh        => $dbh,
 
126
);
 
127
 
 
128
ok(defined $result1, 'Basic call returned results, default schema');
 
129
ok(defined $result2, 'Basic call returned results, specified schema');
 
130
ok(defined $result3, 'Call returned results, default schema, windowed aggs');
 
131
ok(defined $result4, 'Prefixed call returned results, default schema');
 
132
ok($result1->{pg_object_test}, 'Correct value returned for proc result1');
 
133
ok($result2->{pg_object_test}, 'Correct value returned for proc result2');
 
134
ok($result3->{pg_object_test}, 'Correct value returned for proc result3');
 
135
ok($result4->{pg_object_test}, 'Correct value returned for proc result4');
 
136
is($result3->{lines}, 1, 'Correct running agg returned for proc result3');
 
137
 
 
138
$dbh->disconnect;
 
139
$dbh1->do('DROP DATABASE pgobject_test_db');
 
140
$dbh1->disconnect;