Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2225c2f

Browse files
author
Stepan Pesternikov
committed
Added perl tests
1 parent 2f72cc9 commit 2225c2f

29 files changed

+1929
-0
lines changed

test/perl/runtest.pl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::Harness;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
17+
print "Prepare test enviroment\n";
18+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
19+
{PrintError => 0});
20+
if($dbh->err != 0){
21+
print $DBI::errstr . "\n";
22+
exit(-1);
23+
}
24+
25+
my $query = "DROP TABLE IF EXISTS test_results;";
26+
$dbh->do($query);
27+
if($dbh->err != 0){
28+
print $DBI::errstr . "\n";
29+
exit(-1);
30+
}
31+
32+
$query = "CREATE TABLE test_results( time_mark timestamp, commentary text );";
33+
$dbh->do($query);
34+
if($dbh->err != 0){
35+
print $DBI::errstr . "\n";
36+
exit(-1);
37+
}
38+
39+
$query = "DROP ROLE IF EXISTS tester;";
40+
$dbh->do($query);
41+
if($dbh->err != 0){
42+
print $DBI::errstr . "\n";
43+
exit(-1);
44+
}
45+
46+
$query = "CREATE ROLE tester;";
47+
$dbh->do($query);
48+
if($DBI::err != 0){
49+
print $DBI::errstr . "\n";
50+
exit(-1);
51+
}
52+
53+
$query = "GRANT INSERT ON test_results TO tester;";
54+
$dbh->do($query);
55+
if($dbh->err != 0){
56+
print $DBI::errstr . "\n";
57+
exit(-1);
58+
}
59+
60+
$dbh->disconnect();
61+
62+
print "Run tests\n";
63+
my @db_param = ["--host=$host", "--dbname=$dbname", "--username=$username", "--password=$password"];
64+
my %args = (
65+
verbosity => 1,
66+
test_args => @db_param
67+
);
68+
my $harness = TAP::Harness->new( \%args );
69+
my @tests = glob( 't/*.t' );
70+
$harness->runtests(@tests );
71+
72+
73+
74+
75+
76+

test/perl/t/activateJob.t

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
17+
{PrintError => 0});
18+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
19+
20+
my $query = "DELETE FROM test_results;";
21+
$dbh->do($query);
22+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(NULL, '');";
25+
my $sth = $dbh->prepare($query);
26+
$sth->execute();
27+
ok($dbh->err == 0) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
28+
my $job_id = $sth->fetchrow_array() and $sth->finish();
29+
$sth->finish();
30+
31+
$query = "SELECT schedule.deactivate_job(?)";
32+
$sth = $dbh->prepare($query);
33+
$sth->bind_param(1, $job_id);
34+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
35+
$sth->finish();
36+
37+
$query = "SELECT schedule.set_job_attributes(?, \'{ \"name\": \"Test\",
38+
\"cron\": \"* * * * *\",
39+
\"commands\": [\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\",
40+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
41+
\"run_as\": \"tester\",
42+
\"use_same_transaction\": \"true\"
43+
}\')";
44+
$sth = $dbh->prepare($query);
45+
$sth->bind_param(1, $job_id);
46+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
47+
$sth->finish();
48+
49+
$query = "SELECT schedule.activate_job(?)";
50+
$sth = $dbh->prepare($query);
51+
$sth->bind_param(1, $job_id);
52+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
53+
$sth->finish();
54+
55+
sleep 120;
56+
$query = "SELECT count(*) FROM test_results";
57+
$sth = $dbh->prepare($query);
58+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
59+
60+
my $result = $sth->fetchrow_array() and $sth->finish();
61+
ok ($result > 1) or print "Count == 0\n";
62+
63+
$query = "SELECT schedule.deactivate_job(?)";
64+
$sth = $dbh->prepare($query);
65+
$sth->bind_param(1, $job_id);
66+
ok($sth->execute()) or print $DBI::errstr ;
67+
$sth->finish();
68+
69+
$query = "DELETE FROM test_results;";
70+
$dbh->do($query);
71+
ok($dbh->err == 0) or print $DBI::errstr;
72+
73+
$query = "SELECT schedule.drop_job(?)";
74+
$sth = $dbh->prepare($query);
75+
$sth->bind_param(1, $job_id);
76+
ok($sth->execute()) or print $DBI::errstr;
77+
$sth->finish();
78+
79+
$dbh->disconnect();
80+
81+
done_testing();

test/perl/t/createJobWithBadParam.t

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
17+
{PrintError => 0});
18+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
19+
20+
my $query = "DELETE FROM test_results;";
21+
$dbh->do($query);
22+
ok($dbh->err == 0) or print $DBI::errstr . "\n";
23+
24+
$query = "SELECT schedule.create_job(\'abcdefghi\',
25+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
26+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
27+
my $sth = $dbh->prepare($query);
28+
$sth->execute();
29+
ok($dbh->err != 0) or print $DBI::errstr . "\n";
30+
$sth->finish();
31+
32+
$query = "SELECT schedule.create_job(\'*bcdefgh*\',
33+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
34+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
35+
$sth = $dbh->prepare($query);
36+
$sth->execute();
37+
ok($dbh->err != 0) or print $DBI::errstr . "\n";
38+
$sth->finish();
39+
40+
$query = "SELECT schedule.create_job(\'* * * # *\',
41+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
42+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
43+
$sth = $dbh->prepare($query);
44+
$sth->execute();
45+
ok($dbh->err != 0) or print $DBI::errstr . "\n";
46+
$sth->finish();
47+
48+
$query = "SELECT schedule.create_job(\' \',
49+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
50+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
51+
$sth = $dbh->prepare($query);
52+
$sth->execute();
53+
ok($dbh->err != 0) or print $DBI::errstr . "\n";
54+
$sth->finish();
55+
56+
$query = "SELECT schedule.create_job(\'\',
57+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
58+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
59+
$sth = $dbh->prepare($query);
60+
$sth->execute();
61+
ok($dbh->err != 0) or print $DBI::errstr . "\n";
62+
$sth->finish();
63+
64+
$dbh->disconnect();
65+
66+
done_testing();
67+

test/perl/t/createJobWithCron.t

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
17+
{PrintError => 0});
18+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
19+
20+
my $query = "DELETE FROM test_results;";
21+
$dbh->do($query);
22+
ok($dbh->err == 0, $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(\'* * * * *\',
25+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\',
26+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithCron'')\']);";
27+
my $sth = $dbh->prepare($query);
28+
ok($sth->execute(), $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
29+
my $job_id = $sth->fetchrow_array() and $sth->finish();
30+
31+
sleep 120;
32+
$query = "SELECT count(*) FROM test_results";
33+
$sth = $dbh->prepare($query);
34+
ok($sth->execute(), $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
35+
36+
my $result = $sth->fetchrow_array() and $sth->finish();
37+
ok ($result > 1) or print "Count == 0\n";
38+
39+
$query = "SELECT schedule.deactivate_job(?)";
40+
$sth = $dbh->prepare($query);
41+
$sth->bind_param(1, $job_id);
42+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
43+
$sth->finish();
44+
45+
$query = "DELETE FROM test_results;";
46+
$dbh->do($query);
47+
ok($dbh->err == 0, $dbh->errstr) or print $DBI::errstr . "\n";
48+
49+
$query = "SELECT schedule.drop_job(?)";
50+
$sth = $dbh->prepare($query);
51+
$sth->bind_param(1, $job_id);
52+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
53+
$sth->finish();
54+
55+
$dbh->disconnect();
56+
57+
done_testing();
58+

test/perl/t/createJobWithDate.t

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
no warnings;
4+
use Test::More;
5+
use DBI;
6+
use Getopt::Long;
7+
8+
my $dbname;
9+
my $username;
10+
my $password;
11+
my $host;
12+
GetOptions ( "--host=s" => \$host,
13+
"--dbname=s" => \$dbname,
14+
"--username=s" => \$username,
15+
"--password=s" => \$password);
16+
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$password",
17+
{PrintError => 0});
18+
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
19+
20+
my $query = "DELETE FROM test_results;";
21+
$dbh->do($query);
22+
ok($dbh->err == 0, $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
23+
24+
$query = "SELECT schedule.create_job(now() + interval \'1 minute\',
25+
ARRAY[\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithDate'')\',
26+
\'INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJobWithDate'')\']);";
27+
my $sth = $dbh->prepare($query);
28+
ok($sth->execute(), $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
29+
my $job_id = $sth->fetchrow_array() and $sth->finish();
30+
31+
sleep 70;
32+
$query = "SELECT count(*) FROM test_results";
33+
$sth = $dbh->prepare($query);
34+
ok($sth->execute(), $dbh->errstr) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
35+
36+
my $result = $sth->fetchrow_array() and $sth->finish();
37+
ok ($result > 1) or print "Count == 0\n";
38+
39+
$query = "SELECT schedule.deactivate_job(?)";
40+
$sth = $dbh->prepare($query);
41+
$sth->bind_param(1, $job_id);
42+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n" ;
43+
$sth->finish();
44+
45+
$query = "DELETE FROM test_results;";
46+
$dbh->do($query);
47+
ok($dbh->err == 0, $dbh->errstr) or print $DBI::errstr . "\n" ;
48+
49+
$query = "SELECT schedule.drop_job(?)";
50+
$sth = $dbh->prepare($query);
51+
$sth->bind_param(1, $job_id);
52+
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n" ;
53+
$sth->finish();
54+
55+
$dbh->disconnect();
56+
57+
done_testing();
58+

0 commit comments

Comments
 (0)