Skip to content

Commit e255e50

Browse files
authored
add smoke tests for perl, php and ruby (#365)
1 parent 820b846 commit e255e50

File tree

8 files changed

+240
-1
lines changed

8 files changed

+240
-1
lines changed

Diff for: testing/PostgresDockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM --platform=linux/amd64 ubuntu:20.04
22

3-
# install python, libmysqlclient-dev, java, bats, git ruby, perl, cpan
3+
# install python, java, bats, git ruby, perl, cpan
44
ENV DEBIAN_FRONTEND=noninteractive
55
RUN apt update -y && \
66
apt install -y \
@@ -23,6 +23,7 @@ RUN apt update -y && \
2323
bats \
2424
perl \
2525
php \
26+
php-pgsql \
2627
cpanminus \
2728
cmake \
2829
g++ \
@@ -66,6 +67,15 @@ COPY ./testing/postgres-client-tests/node/package-lock.json /postgres-client-tes
6667
WORKDIR /postgres-client-tests/node
6768
RUN npm install
6869

70+
# install cpan dependencies
71+
RUN cpanm --force DBD::Pg
72+
73+
# install ruby dependencies
74+
COPY ./testing/postgres-client-tests/ruby/Gemfile /postgres-client-tests/ruby/
75+
COPY ./testing/postgres-client-tests/ruby/Gemfile.lock /postgres-client-tests/ruby/
76+
WORKDIR /postgres-client-tests/ruby
77+
RUN gem install bundler -v 2.1.4 && bundle install
78+
6979
# install postgres and psql
7080
RUN service postgresql start
7181

Diff for: testing/postgres-client-tests/perl/postgres-test.pl

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use strict;
2+
3+
use DBI;
4+
5+
my $QUERY_RESPONSE = [
6+
{ "create table test (pk int, value int, primary key(pk))" => '0E0' },
7+
{ "insert into test (pk, value) values (0,0)" => 1 },
8+
{ "select * from test" => 1 },
9+
{"call dolt_add('-A');" => '0E0' },
10+
{"call dolt_commit('-m', 'my commit')" => '0E0' },
11+
{"call dolt_checkout('-b', 'mybranch')" => '0E0' },
12+
{"insert into test (pk, value) values (1,1)" => 1 },
13+
{"call dolt_commit('-a', '-m', 'my commit2')" => '0E0' },
14+
{"call dolt_checkout('main')" => '0E0' },
15+
{"call dolt_merge('mybranch')" => '0E0' },
16+
{"select COUNT(*) FROM dolt_log" => 1 },
17+
];
18+
19+
my $user = $ARGV[0];
20+
my $port = $ARGV[1];
21+
my $db = "doltgres";
22+
23+
my $dsn = "DBI:Pg:database=$db;host=127.0.0.1;port=$port";
24+
# Connect to the database
25+
my $dbh = DBI->connect($dsn, $user, "", { PrintError => 0, RaiseError => 1 });
26+
die "failed to connect to database:DBI->errstr()" unless($dbh);
27+
28+
foreach my $query_response ( @{$QUERY_RESPONSE} ) {
29+
my @query_keys = keys %{$query_response};
30+
my $query = $query_keys[0];
31+
my $exp_result = $query_response->{$query};
32+
33+
my $result = $dbh->do($query);
34+
if ( $result != $exp_result ) {
35+
print "QUERY: $query\n";
36+
print "EXPECTED: $exp_result\n";
37+
print "RESULT: $result\n";
38+
exit 1
39+
}
40+
}
41+
42+
# Disconnect from the database
43+
$dbh->disconnect();
44+
45+
exit 0;
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
$user = $argv[1];
3+
$port = $argv[2];
4+
$db = 'doltgres';
5+
6+
$conn = new PDO("pgsql:host=localhost;port={$port};dbname={$db}", $user, '');
7+
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
8+
9+
$queries = [
10+
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))" => 0,
11+
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)" => 1,
12+
"select * from test" => 1,
13+
"call dolt_add('-A');" => 0,
14+
"call dolt_commit('-m', 'my commit')" => 0,
15+
"call dolt_checkout('-b', 'mybranch')" => 0,
16+
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)" => 1,
17+
"call dolt_commit('-a', '-m', 'my commit2')" => 0,
18+
"call dolt_checkout('main')" => 0,
19+
"call dolt_merge('mybranch')" => 0,
20+
"select COUNT(*) FROM dolt_log" => 1
21+
];
22+
23+
foreach ($queries as $query => $expected) {
24+
$result = $conn->query($query);
25+
if ($result->rowCount() != $expected) {
26+
echo "LENGTH: {$result->rowCount()}\n";
27+
echo "QUERY: {$query}\n";
28+
echo "EXPECTED: {$expected}\n";
29+
echo "RESULT: {$result}";
30+
exit(1);
31+
}
32+
}
33+
34+
$result = $conn->query("SELECT * FROM test WHERE pk = 1");
35+
assert(1 == $result->rowCount());
36+
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
37+
assert(1 == $row['pk']);
38+
assert(1 == $row['value']);
39+
assert(123456.789 == $row['d1']);
40+
assert(420.42 == $row['f1']);
41+
}
42+
43+
exit(0)
44+
?>
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
$user = $argv[1];
3+
$port = $argv[2];
4+
$db = 'doltgres';
5+
6+
$conn = pg_connect("host = localhost port = $port dbname = $db user = $user")
7+
or die('Could not connect: ' . pg_result_error());
8+
9+
$queries = [
10+
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))" => 0,
11+
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)" => 0,
12+
"select * from test" => 1,
13+
"call dolt_add('-A');" => 0,
14+
"call dolt_commit('-m', 'my commit')" => 0,
15+
"call dolt_checkout('-b', 'mybranch')" => 0,
16+
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)" => 0,
17+
"call dolt_commit('-a', '-m', 'my commit2')" => 0,
18+
"call dolt_checkout('main')" => 0,
19+
"call dolt_merge('mybranch')" => 0,
20+
"select COUNT(*) FROM dolt_log" => 1
21+
];
22+
23+
foreach ($queries as $query => $expected) {
24+
$result = pg_query($conn, $query);
25+
if (is_bool($result)) {
26+
if (!$result) {
27+
echo "LENGTH: {pg_num_rows($result)}\n";
28+
echo "QUERY: {$query}\n";
29+
echo "EXPECTED: {$expected}\n";
30+
echo "RESULT: {$result}";
31+
exit(1);
32+
}
33+
} else if (pg_num_rows($result) != $expected) {
34+
echo "LENGTH: {pg_num_rows($result)}\n";
35+
echo "QUERY: {$query}\n";
36+
echo "EXPECTED: {$expected}\n";
37+
echo "RESULT: {$result}";
38+
exit(1);
39+
}
40+
}
41+
42+
$result = pg_query($conn, "SELECT * FROM test WHERE pk = 1");
43+
assert(1 == pg_num_rows($result));
44+
while($row = pg_fetch_assoc($result)) {
45+
assert(1 == $row['pk']);
46+
assert(1 == $row['value']);
47+
assert(123456.789 == $row['d1']);
48+
assert(420.42 == $row['f1']);
49+
}
50+
51+
pg_close($conn);
52+
53+
exit(0)
54+
?>

Diff for: testing/postgres-client-tests/postgres-client-tests.bats

+18
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,21 @@ teardown() {
3737
echo $DOLTGRES_VERSION
3838
node $BATS_TEST_DIRNAME/node/knex.js $USER $PORT $DOLTGRES_VERSION
3939
}
40+
41+
@test "perl DBI:Pg client" {
42+
perl $BATS_TEST_DIRNAME/perl/postgres-test.pl $USER $PORT
43+
}
44+
45+
@test "ruby pg test" {
46+
ruby $BATS_TEST_DIRNAME/ruby/pg-test.rb $USER $PORT
47+
}
48+
49+
@test "php pg_connect client" {
50+
cd $BATS_TEST_DIRNAME/php
51+
php pg_connect_test.php $USER $PORT
52+
}
53+
54+
@test "php pdo pgsql client" {
55+
cd $BATS_TEST_DIRNAME/php
56+
php pdo_connector_test.php $USER $PORT
57+
}

Diff for: testing/postgres-client-tests/ruby/Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
gem 'pg'
3+
gem 'test'

Diff for: testing/postgres-client-tests/ruby/Gemfile.lock

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
pg (1.5.6)
5+
rubytest (0.8.1)
6+
test (1.0.0)
7+
rubytest
8+
9+
PLATFORMS
10+
ruby
11+
x86_64-darwin-23
12+
13+
DEPENDENCIES
14+
pg
15+
test
16+
17+
BUNDLED WITH
18+
2.5.9

Diff for: testing/postgres-client-tests/ruby/pg-test.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/ruby
2+
3+
require 'pg'
4+
require 'test/unit'
5+
6+
extend Test::Unit::Assertions
7+
8+
user = ARGV[0]
9+
port = ARGV[1]
10+
db = "doltgres"
11+
12+
queries = [
13+
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))",
14+
"select * from test",
15+
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)",
16+
"select * from test",
17+
"call dolt_add('-A');",
18+
"call dolt_commit('-m', 'my commit')",
19+
"select COUNT(*) FROM dolt_log",
20+
"call dolt_checkout('-b', 'mybranch')",
21+
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)",
22+
"call dolt_commit('-a', '-m', 'my commit2')",
23+
"call dolt_checkout('main')",
24+
"call dolt_merge('mybranch')",
25+
"select COUNT(*) FROM dolt_log",
26+
]
27+
28+
# Smoke test the queries to make sure nothing blows up
29+
conn = PG::Connection.new(:host => "localhost", :user => user, :dbname => db, :port => port)
30+
queries.each do |query|
31+
res = conn.query(query)
32+
end
33+
34+
# Then make sure we can read some data back
35+
res = conn.query("SELECT * from test where pk = 1;")
36+
rowCount = 0
37+
res.each do |row|
38+
rowCount += 1
39+
assert_equal 1, row["pk"].to_i
40+
assert_equal 1, row["value"].to_i
41+
assert_equal 123456.789, row["d1"].to_f
42+
assert_equal 420.42, row["f1"].to_f
43+
end
44+
assert_equal 1, rowCount
45+
46+
conn.close()
47+
exit(0)

0 commit comments

Comments
 (0)