Skip to content

Commit f581d0f

Browse files
committed
get pgtap tests up and running
1 parent 50a2def commit f581d0f

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ services:
2424
- POSTGRES_USER=username
2525
- POSTGRES_PASSWORD=password
2626
- POSTGRES_DB=postgis
27+
- PGUSER=username
28+
- PGPASSWORD=password
29+
- PGDATABASE=postgis
2730
ports:
2831
- "5432:5432"
2932
volumes:

scripts/test

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ Runs tests for the project.
1616

1717
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
1818
echo "Running database tests..."
19-
# TODO: Fix these tests
20-
# scripts/server --detach;
21-
# docker-compose \
22-
# run --rm \
23-
# -e PGUSER=username \
24-
# -e PGPASSWORD=password \
25-
# -e PGHOST=database \
26-
# database /opt/src/test/test.sh;
19+
scripts/server --detach;
20+
docker-compose \
21+
exec \
22+
database /opt/src/test/test.sh;
2723

2824
echo "Running pypgstac tests..."
2925
docker-compose \

test/pgtap.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
\pset format unaligned
77
\pset tuples_only true
88
\pset pager off
9+
\timing off
910

1011
-- Revert all changes on failure.
1112
\set ON_ERROR_ROLLBACK 1
@@ -134,7 +135,6 @@ SELECT has_function('pgstac'::name, 'filter_by_order', ARRAY['item','jsonb','tex
134135
SELECT has_function('pgstac'::name, 'search_dtrange', ARRAY['jsonb']);
135136
SELECT has_function('pgstac'::name, 'search', ARRAY['jsonb']);
136137

137-
138138
-- Finish the tests and clean up.
139139
SELECT * FROM finish();
140140
ROLLBACK;

test/test.sh

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#!/bin/bash
2-
tempid=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 8 | head -n 1)
3-
tempdb="pgstac_tst_${tmpid}"
4-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5-
6-
7-
createdb $tempdb;
8-
export PGDATABASE=$tempdb
9-
10-
cd $DIR/..
11-
psql -f pgstac.sql
12-
13-
14-
cat test/testdata/collections.ndjson | psql -c "copy pgstac.collections_staging FROM stdin"
15-
cat test/testdata/items.ndjson | psql -c "copy pgstac.items_staging FROM stdin"
16-
17-
psql -X -f test/test.sql >/tmp/$tempdb.out
18-
19-
cmp --silent /tmp/$tempdb.out test/test.out && echo '### SUCCESS: Files Tests Pass! ###' || echo '### WARNING: Tests did not pass! ###' && diff /tmp/$tempdb.out test/test.out
20-
21-
dropdb $tempdb;
22-
rm /tmp/$tempdb.out
2+
TESTOUTPUT=$(psql -X -f $(dirname $0)/pgtap.sql)
3+
if [ $? != 0 ]; then
4+
echo "Problem connecting to database to run tests."
5+
exit 1
6+
fi
7+
echo "$TESTOUTPUT" | grep '^not'
8+
if [ $? == 0 ]; then
9+
exit 1
10+
else
11+
echo "All PGTap Tests Passed!"
12+
exit 0
13+
fi

0 commit comments

Comments
 (0)