]> gitweb.factorcode.org Git - factor.git/blob - basis/db/postgresql/postgresql-tests.factor
unicode: make this the API for all unicode things.
[factor.git] / basis / db / postgresql / postgresql-tests.factor
1 USING: accessors alien continuations db db.errors db.queries db.postgresql
2 db.private db.tester db.tuples db.types io classes kernel math namespaces
3 prettyprint sequences system tools.test unicode ;
4 IN: db.postgresql.tests
5
6 : nonexistant-db ( -- db )
7     <postgresql-db>
8         "localhost" >>host
9         "fake-user" >>username
10         "no-pass" >>password
11         "dont-exist" >>database ;
12
13 ! Don't leak connections
14 { } [
15     2000 [ [ nonexistant-db [ ] with-db ] ignore-errors ] times
16 ] unit-test
17
18 ! Ensure the test database exists
19 postgresql-template1-db [
20     postgresql-test-db-name ensure-database
21 ] with-db
22
23 ! Triggers a two line error message (ERROR + DETAIL) because two
24 ! connections can't simultaneously use the template1 database.
25 ! [
26     ! postgresql-template1-db [
27         ! postgresql-template1-db [
28             ! "will_never_exist" ensure-database
29         ! ] with-db
30     ! ] with-db
31 ! ] [ sql-unknown-error? ] must-fail-with
32
33 { } [
34     postgresql-test-db [
35         [ "drop table person;" sql-command ] ignore-errors
36         "create table person (name varchar(30), country varchar(30));"
37             sql-command
38
39         "insert into person values('John', 'America');" sql-command
40         "insert into person values('Jane', 'New Zealand');" sql-command
41     ] with-db
42 ] unit-test
43
44 {
45     {
46         { "John" "America" }
47         { "Jane" "New Zealand" }
48     }
49 } [
50     postgresql-test-db [
51         "select * from person" sql-query
52     ] with-db
53 ] unit-test
54
55 {
56     {
57         { "John" "America" }
58         { "Jane" "New Zealand" }
59     }
60 } [ postgresql-test-db [ "select * from person" sql-query ] with-db ] unit-test
61
62 {
63 } [
64     postgresql-test-db [
65         "insert into person(name, country) values('Jimmy', 'Canada')"
66         sql-command
67     ] with-db
68 ] unit-test
69
70 {
71     {
72         { "John" "America" }
73         { "Jane" "New Zealand" }
74         { "Jimmy" "Canada" }
75     }
76 } [ postgresql-test-db [ "select * from person" sql-query ] with-db ] unit-test
77
78 [
79     postgresql-test-db [
80         [
81             "insert into person(name, country) values('Jose', 'Mexico')" sql-command
82             "insert into person(name, country) values('Jose', 'Mexico')" sql-command
83             "oops" throw
84         ] with-transaction
85     ] with-db
86 ] must-fail
87
88 { 3 } [
89     postgresql-test-db [
90         "select * from person" sql-query length
91     ] with-db
92 ] unit-test
93
94 {
95 } [
96     postgresql-test-db [
97         [
98             "insert into person(name, country) values('Jose', 'Mexico')"
99             sql-command
100             "insert into person(name, country) values('Jose', 'Mexico')"
101             sql-command
102         ] with-transaction
103     ] with-db
104 ] unit-test
105
106 { 5 } [
107     postgresql-test-db [
108         "select * from person" sql-query length
109     ] with-db
110 ] unit-test