]> gitweb.factorcode.org Git - factor.git/blob - basis/db/postgresql/postgresql-tests.factor
Conflict resolution
[factor.git] / basis / db / postgresql / postgresql-tests.factor
1 USING: kernel db.postgresql alien continuations io classes
2 prettyprint sequences namespaces tools.test db db.private
3 db.tuples db.types unicode.case accessors system ;
4 IN: db.postgresql.tests
5
6 : test-db ( -- postgresql-db )
7     <postgresql-db>
8         "localhost" >>host
9         "postgres" >>username
10         "thepasswordistrust" >>password
11         "factor-test" >>database ;
12
13 os windows? cpu x86.64? and [
14     [ ] [ test-db [ ] with-db ] unit-test
15
16     [ ] [
17         test-db [
18             [ "drop table person;" sql-command ] ignore-errors
19             "create table person (name varchar(30), country varchar(30));"
20                 sql-command
21
22             "insert into person values('John', 'America');" sql-command
23             "insert into person values('Jane', 'New Zealand');" sql-command
24         ] with-db
25     ] unit-test
26
27     [
28         {
29             { "John" "America" }
30             { "Jane" "New Zealand" }
31         }
32     ] [
33         test-db [
34             "select * from person" sql-query
35         ] with-db
36     ] unit-test
37
38     [
39         {
40             { "John" "America" }
41             { "Jane" "New Zealand" }
42         }
43     ] [ test-db [ "select * from person" sql-query ] with-db ] unit-test
44
45     [
46     ] [
47         test-db [
48             "insert into person(name, country) values('Jimmy', 'Canada')"
49             sql-command
50         ] with-db
51     ] unit-test
52
53     [
54         {
55             { "John" "America" }
56             { "Jane" "New Zealand" }
57             { "Jimmy" "Canada" }
58         }
59     ] [ test-db [ "select * from person" sql-query ] with-db ] unit-test
60
61     [
62         test-db [
63             [
64                 "insert into person(name, country) values('Jose', 'Mexico')" sql-command
65                 "insert into person(name, country) values('Jose', 'Mexico')" sql-command
66                 "oops" throw
67             ] with-transaction
68         ] with-db
69     ] must-fail
70
71     [ 3 ] [
72         test-db [
73             "select * from person" sql-query length
74         ] with-db
75     ] unit-test
76
77     [
78     ] [
79         test-db [
80             [
81                 "insert into person(name, country) values('Jose', 'Mexico')"
82                 sql-command
83                 "insert into person(name, country) values('Jose', 'Mexico')"
84                 sql-command
85             ] with-transaction
86         ] with-db
87     ] unit-test
88
89     [ 5 ] [
90         test-db [
91             "select * from person" sql-query length
92         ] with-db
93     ] unit-test
94 ] unless