-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add smoke tests for perl, php and ruby (#365)
- Loading branch information
1 parent
820b846
commit e255e50
Showing
8 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use strict; | ||
|
||
use DBI; | ||
|
||
my $QUERY_RESPONSE = [ | ||
{ "create table test (pk int, value int, primary key(pk))" => '0E0' }, | ||
{ "insert into test (pk, value) values (0,0)" => 1 }, | ||
{ "select * from test" => 1 }, | ||
{"call dolt_add('-A');" => '0E0' }, | ||
{"call dolt_commit('-m', 'my commit')" => '0E0' }, | ||
{"call dolt_checkout('-b', 'mybranch')" => '0E0' }, | ||
{"insert into test (pk, value) values (1,1)" => 1 }, | ||
{"call dolt_commit('-a', '-m', 'my commit2')" => '0E0' }, | ||
{"call dolt_checkout('main')" => '0E0' }, | ||
{"call dolt_merge('mybranch')" => '0E0' }, | ||
{"select COUNT(*) FROM dolt_log" => 1 }, | ||
]; | ||
|
||
my $user = $ARGV[0]; | ||
my $port = $ARGV[1]; | ||
my $db = "doltgres"; | ||
|
||
my $dsn = "DBI:Pg:database=$db;host=127.0.0.1;port=$port"; | ||
# Connect to the database | ||
my $dbh = DBI->connect($dsn, $user, "", { PrintError => 0, RaiseError => 1 }); | ||
die "failed to connect to database:DBI->errstr()" unless($dbh); | ||
|
||
foreach my $query_response ( @{$QUERY_RESPONSE} ) { | ||
my @query_keys = keys %{$query_response}; | ||
my $query = $query_keys[0]; | ||
my $exp_result = $query_response->{$query}; | ||
|
||
my $result = $dbh->do($query); | ||
if ( $result != $exp_result ) { | ||
print "QUERY: $query\n"; | ||
print "EXPECTED: $exp_result\n"; | ||
print "RESULT: $result\n"; | ||
exit 1 | ||
} | ||
} | ||
|
||
# Disconnect from the database | ||
$dbh->disconnect(); | ||
|
||
exit 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
$user = $argv[1]; | ||
$port = $argv[2]; | ||
$db = 'doltgres'; | ||
|
||
$conn = new PDO("pgsql:host=localhost;port={$port};dbname={$db}", $user, ''); | ||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
$queries = [ | ||
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))" => 0, | ||
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)" => 1, | ||
"select * from test" => 1, | ||
"call dolt_add('-A');" => 0, | ||
"call dolt_commit('-m', 'my commit')" => 0, | ||
"call dolt_checkout('-b', 'mybranch')" => 0, | ||
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)" => 1, | ||
"call dolt_commit('-a', '-m', 'my commit2')" => 0, | ||
"call dolt_checkout('main')" => 0, | ||
"call dolt_merge('mybranch')" => 0, | ||
"select COUNT(*) FROM dolt_log" => 1 | ||
]; | ||
|
||
foreach ($queries as $query => $expected) { | ||
$result = $conn->query($query); | ||
if ($result->rowCount() != $expected) { | ||
echo "LENGTH: {$result->rowCount()}\n"; | ||
echo "QUERY: {$query}\n"; | ||
echo "EXPECTED: {$expected}\n"; | ||
echo "RESULT: {$result}"; | ||
exit(1); | ||
} | ||
} | ||
|
||
$result = $conn->query("SELECT * FROM test WHERE pk = 1"); | ||
assert(1 == $result->rowCount()); | ||
while($row = $result->fetch(PDO::FETCH_ASSOC)) { | ||
assert(1 == $row['pk']); | ||
assert(1 == $row['value']); | ||
assert(123456.789 == $row['d1']); | ||
assert(420.42 == $row['f1']); | ||
} | ||
|
||
exit(0) | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
$user = $argv[1]; | ||
$port = $argv[2]; | ||
$db = 'doltgres'; | ||
|
||
$conn = pg_connect("host = localhost port = $port dbname = $db user = $user") | ||
or die('Could not connect: ' . pg_result_error()); | ||
|
||
$queries = [ | ||
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))" => 0, | ||
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)" => 0, | ||
"select * from test" => 1, | ||
"call dolt_add('-A');" => 0, | ||
"call dolt_commit('-m', 'my commit')" => 0, | ||
"call dolt_checkout('-b', 'mybranch')" => 0, | ||
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)" => 0, | ||
"call dolt_commit('-a', '-m', 'my commit2')" => 0, | ||
"call dolt_checkout('main')" => 0, | ||
"call dolt_merge('mybranch')" => 0, | ||
"select COUNT(*) FROM dolt_log" => 1 | ||
]; | ||
|
||
foreach ($queries as $query => $expected) { | ||
$result = pg_query($conn, $query); | ||
if (is_bool($result)) { | ||
if (!$result) { | ||
echo "LENGTH: {pg_num_rows($result)}\n"; | ||
echo "QUERY: {$query}\n"; | ||
echo "EXPECTED: {$expected}\n"; | ||
echo "RESULT: {$result}"; | ||
exit(1); | ||
} | ||
} else if (pg_num_rows($result) != $expected) { | ||
echo "LENGTH: {pg_num_rows($result)}\n"; | ||
echo "QUERY: {$query}\n"; | ||
echo "EXPECTED: {$expected}\n"; | ||
echo "RESULT: {$result}"; | ||
exit(1); | ||
} | ||
} | ||
|
||
$result = pg_query($conn, "SELECT * FROM test WHERE pk = 1"); | ||
assert(1 == pg_num_rows($result)); | ||
while($row = pg_fetch_assoc($result)) { | ||
assert(1 == $row['pk']); | ||
assert(1 == $row['value']); | ||
assert(123456.789 == $row['d1']); | ||
assert(420.42 == $row['f1']); | ||
} | ||
|
||
pg_close($conn); | ||
|
||
exit(0) | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
gem 'pg' | ||
gem 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
pg (1.5.6) | ||
rubytest (0.8.1) | ||
test (1.0.0) | ||
rubytest | ||
|
||
PLATFORMS | ||
ruby | ||
x86_64-darwin-23 | ||
|
||
DEPENDENCIES | ||
pg | ||
test | ||
|
||
BUNDLED WITH | ||
2.5.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/ruby | ||
|
||
require 'pg' | ||
require 'test/unit' | ||
|
||
extend Test::Unit::Assertions | ||
|
||
user = ARGV[0] | ||
port = ARGV[1] | ||
db = "doltgres" | ||
|
||
queries = [ | ||
"create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))", | ||
"select * from test", | ||
"insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)", | ||
"select * from test", | ||
"call dolt_add('-A');", | ||
"call dolt_commit('-m', 'my commit')", | ||
"select COUNT(*) FROM dolt_log", | ||
"call dolt_checkout('-b', 'mybranch')", | ||
"insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)", | ||
"call dolt_commit('-a', '-m', 'my commit2')", | ||
"call dolt_checkout('main')", | ||
"call dolt_merge('mybranch')", | ||
"select COUNT(*) FROM dolt_log", | ||
] | ||
|
||
# Smoke test the queries to make sure nothing blows up | ||
conn = PG::Connection.new(:host => "localhost", :user => user, :dbname => db, :port => port) | ||
queries.each do |query| | ||
res = conn.query(query) | ||
end | ||
|
||
# Then make sure we can read some data back | ||
res = conn.query("SELECT * from test where pk = 1;") | ||
rowCount = 0 | ||
res.each do |row| | ||
rowCount += 1 | ||
assert_equal 1, row["pk"].to_i | ||
assert_equal 1, row["value"].to_i | ||
assert_equal 123456.789, row["d1"].to_f | ||
assert_equal 420.42, row["f1"].to_f | ||
end | ||
assert_equal 1, rowCount | ||
|
||
conn.close() | ||
exit(0) |