Testsuite: tweak pgsql testcase
[exim.git] / test / scripts / 2620-Postgresql / 2620
1 # pgsql lookups
2 # The pgsql-devel (or equivalent) package will be need for Exim to build, and
3 # the postgresql-server (or equivalent) package for this test to run.
4 #
5 # first, populate a DB to test against
6 sudo rm -fr DIR/pgsql
7 echo Starting DB server
8 perl
9 system 'DIR/bin.sys/initdb -D DIR/pgsql/data';
10 ****
11 #
12 # I don not understand why, but the DB fails to start if this rm is present.
13 #sudo rm test-stdout
14 #
15 # Start the DB server
16 background
17 DIR/bin.sys/postgres -D DIR/pgsql/data -p PORT_N -k DIR/pgsql
18 ****
19 #
20 sleep 1
21 echo Waiting for DB server
22 perl
23 system 'DIR/bin.sys/pg_ctl -w -D DIR/pgsql/data status';
24 system 'createdb -h localhost -p PORT_N test';
25 system 'psql -h localhost -p PORT_N -d test \
26  -c "CREATE TABLE them ( name text, id text ); \
27      INSERT INTO them VALUES ( \'Philip Hazel\', \'ph10\' ); \
28      INSERT INTO them VALUES ( \'Aristotle\',    \'aaaa\' ); \
29      INSERT INTO them VALUES ( \'\', \'nothing\' ); \
30      INSERT INTO them VALUES ( \'\"stquot\', \'quote2\' ); \
31      INSERT INTO them VALUES ( \'before\' || CHR(13) || CHR(10) || \'after\', \'newline\' ); \
32      INSERT INTO them VALUES ( \'x\' || CHR(9) || \'x\', \'tab\' ); \
33      INSERT INTO them VALUES ( CHR(39) || \'stquot\', \'quote1\' );" \
34  ';
35 ****
36 #
37 echo Populated DB server
38 #
39 # now, the tests
40 exim -d-all+lookup -be
41 ${lookup pgsql {select name from them where id='ph10';}}
42 ${lookup pgsql {select name from them where id='ph10';}}
43 ${lookup pgsql {select name from them where id='xxxx';}}
44 ${lookup pgsql {select name from them where id='nothing';}}
45 ${lookup pgsql {select id,name from them where id='nothing';}}
46 ${lookup pgsql {delete from them where id='nonexist';}}
47 ${lookup pgsql {select * from them where id='quote2';}}
48 ${lookup pgsql {select * from them where id='newline';}}
49 ${lookup pgsql {select * from them where id='tab';}}
50 ${lookup pgsql {select * from them where name='${quote_pgsql:'stquot}';}}
51 ${lookup pgsql {servers=x:localhost; select name from them where id='ph10';}}
52 ${lookup pgsql {servers=localhost::PORT_N:x; select name from them where id='ph10';}}
53 ${lookup pgsql {servers=localhost::PORT_N/test/CALLER/:x; select name from them where id='ph10';}}
54 ${lookup pgsql {servers=(DIR/pgsql/.s.PGSQL.PORT_N)/test/CALLER/:x; select name from them where id='ph10';}}
55 x
56 ${lookup pgsql {SELECT name FROM them WHERE id IN ('ph10', 'aaaa');}}
57 ${lookup pgsql {SELECT *    FROM them WHERE id IN ('ph10', 'aaaa');}}
58 ${lookup pgsql {delete from them where id='aaaa'}}
59 ****
60 exim -d -bh 10.0.0.0
61 helo test
62 mail from:<a@b>
63 rcpt to:<c@d>
64 rcpt to:<c@d>
65 quit
66 ****
67 exim -odi -d CALLER
68 Test message
69 .
70 ****
71 exim -DSERVERS=\(DIR/pgsql/.s.PGSQL.PORT_N\)/test/CALLER/ -d-all+lookup -be
72 ${lookup pgsql {select name from them where id='ph10';}}
73 ****
74 #
75 perl
76 system 'DIR/bin.sys/pg_ctl stop -D DIR/pgsql/data -m immediate';
77 ****
78 sleep 2
79 killdaemon
80 sudo rm -fr DIR/pgsql