Browse Source

Attempt to use our own, "self-contained" Postgres

David N. Welton 10 years ago
parent
commit
f210904c88
6 changed files with 53 additions and 7 deletions
  1. 1 0
      .gitignore
  2. 4 2
      Makefile
  3. 30 0
      setup_test_db.sh
  4. 8 0
      start_test_db.sh
  5. 8 4
      test/epgsql_tests.erl
  6. 2 1
      test_data/test_schema.sql

+ 1 - 0
.gitignore

@@ -4,3 +4,4 @@
 /ebin/
 /.eunit/
 rebar
+datadir/

+ 4 - 2
Makefile

@@ -12,8 +12,10 @@ clean:
 # The INSERT is used to make sure the schema_version matches the tests
 # being run.
 create_testdbs:
-	psql template1 < ./test_data/test_schema.sql
-	psql epgsql_test_db1 -c "INSERT INTO schema_version (version) VALUES ('${LASTVERSION}');"
+	# Uses the test environment set up with setup_test_db.sh
+	echo "CREATE DATABASE davidw;" | psql -h localhost -p 10432 template1
+	psql -h localhost -p 10432 template1 < ./test_data/test_schema.sql
+	psql -h localhost -p 10432 epgsql_test_db1 -c "INSERT INTO schema_version (version) VALUES ('${LASTVERSION}');"
 
 test:
 	@$(REBAR) eunit

+ 30 - 0
setup_test_db.sh

@@ -0,0 +1,30 @@
+#!/bin/sh
+
+if [ -z $(which initdb) ] ; then
+    echo "Postgres not found, you may need to launch like so: PATH=\$PATH:/usr/lib/postgresql/9.3/bin/ $0"
+    exit 1
+fi
+
+## Thanks to Matwey V. Kornilov ( https://github.com/matwey ) for
+## this:
+
+initdb --locale en_US.UTF-8 datadir
+echo "ssl = on" >> datadir/postgresql.conf
+
+cp test_data/epgsql.crt datadir/server.crt
+cp test_data/epgsql.key datadir/server.key
+cp test_data/root.crt datadir/root.crt
+cp test_data/root.key datadir/root.key
+chmod 0600 datadir/server.key
+
+cat > datadir/pg_hba.conf <<EOF
+local   all             $USER                                   trust
+host    template1	$USER                   127.0.0.1/32    trust
+host    $USER           $USER                   127.0.0.1/32    trust
+host    epgsql_test_db1 $USER                   127.0.0.1/32    trust
+host    epgsql_test_db1 epgsql_test             127.0.0.1/32    trust
+host    epgsql_test_db1 epgsql_test_md5         127.0.0.1/32    md5
+host    epgsql_test_db1 epgsql_test_cleartext   127.0.0.1/32    password
+hostssl epgsql_test_db1 epgsql_test_cert        127.0.0.1/32    cert
+EOF
+

+ 8 - 0
start_test_db.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+if [ -z $(which postgres) ] ; then
+    echo "Postgres not found, you may need to launch like so: PATH=\$PATH:/usr/lib/postgresql/9.3/bin/ $0"
+    exit 1
+fi
+
+postgres -D datadir/ -p 10432 -k `pwd`/datadir/

+ 8 - 4
test/epgsql_tests.erl

@@ -8,7 +8,7 @@
 -include("epgsql.hrl").
 
 -define(host, "localhost").
--define(port, 5432).
+-define(port, 10432).
 
 -define(ssl_apps, [crypto, asn1, public_key, ssl]).
 
@@ -573,9 +573,13 @@ hstore_type_test(Module) ->
         {[{<<"a">>, <<"c">>}, {<<"c">>, <<"d">>}]},
         {[{<<"a">>, <<"c">>}, {<<"c">>, null}]}
     ],
-    check_type(Module, hstore, "''", {[]}, []),
-    check_type(Module, hstore, "'a => 1, b => 2.0, c => null'",
-               {[{<<"c">>, null}, {<<"b">>, <<"2.0">>}, {<<"a">>, <<"1">>}]}, Values).
+    with_connection(
+      Module,
+      fun(C) ->
+              check_type(Module, hstore, "''", {[]}, []),
+              check_type(Module, hstore, "'a => 1, b => 2.0, c => null'",
+                         {[{<<"c">>, null}, {<<"b">>, <<"2.0">>}, {<<"a">>, <<"1">>}]}, Values)
+      end).
 
 net_type_test(Module) ->
     check_type(Module, cidr, "'127.0.0.1/32'", {{127,0,0,1}, 32}, [{{127,0,0,1}, 32}, {{0,0,0,0,0,0,0,1}, 128}]),

+ 2 - 1
test_data/test_schema.sql

@@ -48,6 +48,7 @@ CREATE TABLE schema_version (version varchar);
 -- This requires Postgres to be compiled with SSL:
 -- http://www.postgresql.org/docs/9.4/static/sslinfo.html
 CREATE EXTENSION sslinfo;
+
 CREATE EXTENSION hstore;
 CREATE EXTENSION postgis;
 
@@ -76,7 +77,7 @@ CREATE TABLE test_table2 (
   c_interval interval,
   c_hstore hstore,
   c_point point,
-   c_geometry geometry,
+  c_geometry geometry,
   c_cidr cidr,
   c_inet inet);