2014-09-30 08:53:22 -04:00
|
|
|
USING: accessors alien continuations db db.errors db.queries db.postgresql
|
|
|
|
db.private db.tester db.tuples db.types io classes kernel math namespaces
|
2016-03-31 02:29:48 -04:00
|
|
|
prettyprint sequences system tools.test unicode ;
|
2008-03-01 17:00:45 -05:00
|
|
|
IN: db.postgresql.tests
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2014-09-22 14:32:26 -04:00
|
|
|
: nonexistant-db ( -- db )
|
|
|
|
<postgresql-db>
|
|
|
|
"localhost" >>host
|
|
|
|
"fake-user" >>username
|
|
|
|
"no-pass" >>password
|
|
|
|
"dont-exist" >>database ;
|
|
|
|
|
|
|
|
! Don't leak connections
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [
|
2014-09-22 14:32:26 -04:00
|
|
|
2000 [ [ nonexistant-db [ ] with-db ] ignore-errors ] times
|
|
|
|
] unit-test
|
2011-09-04 17:52:44 -04:00
|
|
|
|
2014-08-17 16:07:56 -04:00
|
|
|
! Ensure the test database exists
|
2014-09-30 08:53:22 -04:00
|
|
|
postgresql-template1-db [
|
|
|
|
postgresql-test-db-name ensure-database
|
|
|
|
] with-db
|
|
|
|
|
|
|
|
! Triggers a two line error message (ERROR + DETAIL) because two
|
|
|
|
! connections can't simultaneously use the template1 database.
|
2014-10-08 13:12:16 -04:00
|
|
|
! [
|
|
|
|
! postgresql-template1-db [
|
|
|
|
! postgresql-template1-db [
|
|
|
|
! "will_never_exist" ensure-database
|
|
|
|
! ] with-db
|
|
|
|
! ] with-db
|
|
|
|
! ] [ sql-unknown-error? ] must-fail-with
|
2008-02-03 16:06:31 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
[ "drop table person;" sql-command ] ignore-errors
|
|
|
|
"create table person (name varchar(30), country varchar(30));"
|
|
|
|
sql-command
|
2008-02-03 16:06:31 -05:00
|
|
|
|
2014-07-08 02:26:12 -04:00
|
|
|
"insert into person values('John', 'America');" sql-command
|
|
|
|
"insert into person values('Jane', 'New Zealand');" sql-command
|
|
|
|
] with-db
|
|
|
|
] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{
|
2014-07-08 02:26:12 -04:00
|
|
|
{
|
|
|
|
{ "John" "America" }
|
|
|
|
{ "Jane" "New Zealand" }
|
|
|
|
}
|
2015-07-03 12:39:59 -04:00
|
|
|
} [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
"select * from person" sql-query
|
|
|
|
] with-db
|
|
|
|
] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{
|
2014-07-08 02:26:12 -04:00
|
|
|
{
|
|
|
|
{ "John" "America" }
|
|
|
|
{ "Jane" "New Zealand" }
|
|
|
|
}
|
2015-07-03 12:39:59 -04:00
|
|
|
} [ postgresql-test-db [ "select * from person" sql-query ] with-db ] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{
|
|
|
|
} [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
"insert into person(name, country) values('Jimmy', 'Canada')"
|
|
|
|
sql-command
|
|
|
|
] with-db
|
|
|
|
] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{
|
2014-07-08 02:26:12 -04:00
|
|
|
{
|
|
|
|
{ "John" "America" }
|
|
|
|
{ "Jane" "New Zealand" }
|
|
|
|
{ "Jimmy" "Canada" }
|
|
|
|
}
|
2015-07-03 12:39:59 -04:00
|
|
|
} [ postgresql-test-db [ "select * from person" sql-query ] with-db ] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2014-07-08 02:26:12 -04:00
|
|
|
[
|
|
|
|
postgresql-test-db [
|
|
|
|
[
|
|
|
|
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
|
|
|
|
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
|
|
|
|
"oops" throw
|
|
|
|
] with-transaction
|
|
|
|
] with-db
|
|
|
|
] must-fail
|
2008-02-03 16:06:31 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ 3 } [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
"select * from person" sql-query length
|
|
|
|
] with-db
|
|
|
|
] unit-test
|
2008-02-03 16:06:31 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{
|
|
|
|
} [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
[
|
|
|
|
"insert into person(name, country) values('Jose', 'Mexico')"
|
|
|
|
sql-command
|
|
|
|
"insert into person(name, country) values('Jose', 'Mexico')"
|
|
|
|
sql-command
|
|
|
|
] with-transaction
|
|
|
|
] with-db
|
|
|
|
] unit-test
|
2008-02-03 16:06:31 -05:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ 5 } [
|
2014-07-08 02:26:12 -04:00
|
|
|
postgresql-test-db [
|
|
|
|
"select * from person" sql-query length
|
|
|
|
] with-db
|
2014-09-22 14:32:26 -04:00
|
|
|
] unit-test
|