diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..7515993 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,65 @@ +name: Compilable against Ubuntu packages test instead of full C complex CI + +on: [push, pull_request] + +jobs: + linux: + + runs-on: ubuntu-latest + + name: "CI" + strategy: + fail-fast: true + matrix: + pg: ["14", "15", "16", "17", "18"] + config: ["default", "postgis"] + + steps: + + - name: 'Check Out' + uses: actions/checkout@v4 + + - name: 'Raise Priority for apt.postgresql.org' + run: | + cat << EOF >> ./pgdg.pref + Package: * + Pin: release o=apt.postgresql.org + Pin-Priority: 600 + EOF + sudo mv ./pgdg.pref /etc/apt/preferences.d/ + sudo apt update + + - name: 'Install PostgreSQL' + run: | + sudo apt-get purge postgresql-* + #sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg-snapshot main ${{ matrix.pg }}" > /etc/apt/sources.list.d/pgdg.list' + #curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null + sudo apt-get update + sudo apt-get -y install postgresql-${{ matrix.pg }} postgresql-server-dev-${{ matrix.pg }} postgresql-client-${{ matrix.pg }} + [ "${{ matrix.config }}" == "postgis" ] && sudo apt-get -y install postgresql-${{ matrix.pg }}-postgis-3 + + - name: 'Install Redis + Hiredis' + run: | + sudo apt-get -y install libhiredis-dev redis-server + + - name: 'Start PostgreSQL' + run: | + export PGVER=${{ matrix.pg }} + export PGDATA=/var/lib/postgresql/$PGVER/main + export PGETC=/etc/postgresql/$PGVER/main + export PGBIN=/usr/lib/postgresql/$PGVER/bin + sudo chmod -R 755 /home/`whoami` + sudo cp ./GitHubActions/pg_hba.conf $PGETC/pg_hba.conf + sudo systemctl stop postgresql + sudo pg_ctlcluster $PGVER main start + sudo pg_lsclusters + + - name: 'Build & Test' + run: | + export PATH=/usr/lib/postgresql/${{ matrix.pg }}/bin/:$PATH + export PG_CONFIG=/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config + export PG_CFLAGS=-Werror + [ "${{ matrix.config }}" == "postgis" ] && export ENABLE_GIS=1 + make + sudo -E make PG_CONFIG=$PG_CONFIG install + PGUSER=postgres make installcheck || (cat regression.diffs && /bin/false) diff --git a/GitHubActions/pg_hba.conf b/GitHubActions/pg_hba.conf new file mode 100644 index 0000000..16fda31 --- /dev/null +++ b/GitHubActions/pg_hba.conf @@ -0,0 +1,8 @@ +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all postgres trust +# IPv4 local connections: +host all postgres 127.0.0.1/32 trust +# IPv6 local connections: +host all postgres ::1/128 trust diff --git a/Makefile b/Makefile index 374c688..b618183 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,19 @@ OBJS = redis_fdw.o EXTENSION = redis_fdw DATA = redis_fdw--1.0.sql redis_fdw--2.0.sql redis_fdw--1.0--2.0.sql -REGRESS = redis_fdw -REGRESS_OPTS = --inputdir=test --outputdir=test \ - --load-extension=hstore \ - --load-extension=$(EXTENSION) +ifdef ENABLE_GIS +override PG_CFLAGS += -DREDIS_FDW_GIS_ENABLE +GISTEST=postgis +else +GISTEST=nogis +endif + +ifndef REGRESS +REGRESS = redis_fdw $(GISTEST) +#encodings # future test modules +endif + +REGRESS_OPTS = --encoding=utf8 --inputdir=test --outputdir=test EXTRA_CLEAN = sql/redis_fdw.sql expected/redis_fdw.out diff --git a/test/expected/nogis.out b/test/expected/nogis.out new file mode 100644 index 0000000..cf309cd --- /dev/null +++ b/test/expected/nogis.out @@ -0,0 +1,23 @@ +-- Testcase 001 +CREATE EXTENSION hstore; +-- Testcase 002 +CREATE EXTENSION redis_fdw; +-- Testcase 003 +create server localredis foreign data wrapper redis_fdw; +-- Testcase 004 +create user mapping for public server localredis; +-- Testcase 005 +-- \! redis-cli < test/redis_gis_ini +-- REDIS SPATIAL VALUE TESTS WILL BE HERE +-- Testcase 098 +-- all done, so now blow everything in the db away again +\! redis-cli < test/redis_clean +OK +OK +-- Testcase 099 +DROP EXTENSION redis_fdw CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to server localredis +drop cascades to user mapping for public on server localredis +-- Testcase 100 +DROP EXTENSION hstore CASCADE; diff --git a/test/expected/postgis.out b/test/expected/postgis.out new file mode 100644 index 0000000..b84d7cb --- /dev/null +++ b/test/expected/postgis.out @@ -0,0 +1,29 @@ +-- Testcase 001 +CREATE EXTENSION postgis; +ERROR: extension "postgis" is not available +HINT: The extension must first be installed on the system where PostgreSQL is running. +-- Testcase 002 +CREATE EXTENSION hstore; +-- Testcase 003 +CREATE EXTENSION redis_fdw; +-- Testcase 004 +create server localredis foreign data wrapper redis_fdw; +-- Testcase 005 +create user mapping for public server localredis; +-- Testcase 006 +-- \! redis-cli < test/redis_gis_ini +-- Testcase 098 +-- all done, so now blow everything in the db away again +\! redis-cli < test/redis_clean +OK +OK +-- Testcase 099 +DROP EXTENSION redis_fdw CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to server localredis +drop cascades to user mapping for public on server localredis +-- Testcase 100 +DROP EXTENSION hstore CASCADE; +-- Testcase 101 +DROP EXTENSION postgis CASCADE; +ERROR: extension "postgis" does not exist diff --git a/test/expected/redis_fdw.out b/test/expected/redis_fdw.out index 7c2841b..7b5789d 100644 --- a/test/expected/redis_fdw.out +++ b/test/expected/redis_fdw.out @@ -1,11 +1,29 @@ +-- Testcase 001: +CREATE EXTENSION hstore; +-- Testcase 002: +CREATE EXTENSION redis_fdw; +-- Testcase 003: +select redis_fdw_version(); + redis_fdw_version +------------------- + 1901 +(1 row) + +-- Testcase 004: +select redis_fdw_hiredis_version(); + redis_fdw_hiredis_version +--------------------------- + 1401 +(1 row) + +-- Testcase 005: CREATE OR REPLACE FUNCTION atsort( a text[]) RETURNS text[] LANGUAGE sql IMMUTABLE STRICT AS $function$ select array(select unnest($1) order by 1) -$function$ -; +$function$; create server localredis foreign data wrapper redis_fdw; create user mapping for public server localredis; -- tables for all 5 data types (4 structured plus scalar) @@ -44,7 +62,7 @@ do $$ $$; \unset ON_ERROR_STOP -- ok, empty, so now run the setup script -\! redis-cli < test/sql/redis_setup +\! redis-cli < test/redis_setup OK OK OK @@ -378,7 +396,7 @@ select * from db15_1key_zset_scores order by score desc; -- insert delete update -- first clean the database again -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean OK OK -- singleton scalar table @@ -1342,7 +1360,7 @@ select * from db15_w_hash_kset; (0 rows) -- now clean up for the cursor tests -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean OK OK -- cursor tests @@ -1395,6 +1413,54 @@ select count(*) from db15bigkeysetscalar; (1 row) -- all done, so now blow everything in the db away again -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean OK OK +DROP EXTENSION redis_fdw CASCADE; +NOTICE: drop cascades to 45 other objects +DETAIL: drop cascades to server localredis +drop cascades to user mapping for public on server localredis +drop cascades to foreign table db15 +drop cascades to foreign table db15_hash +drop cascades to foreign table db15_set +drop cascades to foreign table db15_list +drop cascades to foreign table db15_zset +drop cascades to foreign table db15_hash_prefix +drop cascades to foreign table db15_hash_prefix_array +drop cascades to foreign table db15_hash_keyset_array +drop cascades to foreign table db15_set_prefix +drop cascades to foreign table db15_set_prefix_array +drop cascades to foreign table db15_set_keyset_array +drop cascades to foreign table db15_list_prefix +drop cascades to foreign table db15_list_prefix_array +drop cascades to foreign table db15_list_keyset_array +drop cascades to foreign table db15_zset_prefix +drop cascades to foreign table db15_zset_prefix_array +drop cascades to foreign table db15_zset_keyset_array +drop cascades to foreign table db15_1key +drop cascades to foreign table db15_1key_hash +drop cascades to foreign table db15_1key_set +drop cascades to foreign table db15_1key_list +drop cascades to foreign table db15_1key_zset +drop cascades to foreign table db15_1key_zset_scores +drop cascades to foreign table db15_w_1key_scalar +drop cascades to foreign table db15_w_1key_hash +drop cascades to foreign table db15_w_1key_list +drop cascades to foreign table db15_w_1key_set +drop cascades to foreign table db15_w_1key_zset +drop cascades to foreign table db15_w_1key_zsetx +drop cascades to foreign table db15_w_scalar +drop cascades to foreign table db15_w_scalar_pfx +drop cascades to foreign table db15_w_scalar_kset +drop cascades to foreign table db15_w_set_nonarr +drop cascades to foreign table db15_w_set_pfx +drop cascades to foreign table db15_w_set_kset +drop cascades to foreign table db15_w_list_pfx +drop cascades to foreign table db15_w_list_kset +drop cascades to foreign table db15_w_zset_pfx +drop cascades to foreign table db15_w_zset_kset +drop cascades to foreign table db15_w_hash_pfx +drop cascades to foreign table db15_w_hash_kset +drop cascades to foreign table db15bigprefixscalar +drop cascades to foreign table db15bigkeysetscalar +DROP EXTENSION hstore; diff --git a/test/sql/redis_clean b/test/redis_clean similarity index 95% rename from test/sql/redis_clean rename to test/redis_clean index 4a96e9e..fd2a8ec 100644 --- a/test/sql/redis_clean +++ b/test/redis_clean @@ -1,4 +1,3 @@ select 15 flushdb - diff --git a/test/sql/redis_setup b/test/redis_setup similarity index 99% rename from test/sql/redis_setup rename to test/redis_setup index 3c6f2c9..a3b157c 100644 --- a/test/sql/redis_setup +++ b/test/redis_setup @@ -19,7 +19,3 @@ sadd hkeys hash1 hash2 sadd lkeys list1 list2 sadd skeys set1 set2 sadd zkeys zset1 zset2 - - - - diff --git a/test/sql/nogis.sql b/test/sql/nogis.sql new file mode 100644 index 0000000..f766e69 --- /dev/null +++ b/test/sql/nogis.sql @@ -0,0 +1,23 @@ +-- Testcase 001 +CREATE EXTENSION hstore; +-- Testcase 002 +CREATE EXTENSION redis_fdw; + +-- Testcase 003 +create server localredis foreign data wrapper redis_fdw; +-- Testcase 004 +create user mapping for public server localredis; + +-- Testcase 005 +-- \! redis-cli < test/redis_gis_ini + +-- REDIS SPATIAL VALUE TESTS WILL BE HERE + +-- Testcase 098 +-- all done, so now blow everything in the db away again +\! redis-cli < test/redis_clean + +-- Testcase 099 +DROP EXTENSION redis_fdw CASCADE; +-- Testcase 100 +DROP EXTENSION hstore CASCADE; diff --git a/test/sql/postgis.sql b/test/sql/postgis.sql new file mode 100644 index 0000000..e166f99 --- /dev/null +++ b/test/sql/postgis.sql @@ -0,0 +1,26 @@ +-- Testcase 001 +CREATE EXTENSION postgis; +-- Testcase 002 +CREATE EXTENSION hstore; +-- Testcase 003 +CREATE EXTENSION redis_fdw; + +-- Testcase 004 +create server localredis foreign data wrapper redis_fdw; +-- Testcase 005 +create user mapping for public server localredis; + +-- Testcase 006 +-- \! redis-cli < test/redis_gis_ini + + +-- Testcase 098 +-- all done, so now blow everything in the db away again +\! redis-cli < test/redis_clean + +-- Testcase 099 +DROP EXTENSION redis_fdw CASCADE; +-- Testcase 100 +DROP EXTENSION hstore CASCADE; +-- Testcase 101 +DROP EXTENSION postgis CASCADE; diff --git a/test/sql/redis_fdw.sql b/test/sql/redis_fdw.sql index b74e0f0..ee832d2 100644 --- a/test/sql/redis_fdw.sql +++ b/test/sql/redis_fdw.sql @@ -1,15 +1,21 @@ +-- Testcase 001: +CREATE EXTENSION hstore; +-- Testcase 002: +CREATE EXTENSION redis_fdw; +-- Testcase 003: +select redis_fdw_version(); +-- Testcase 004: +select redis_fdw_hiredis_version(); + +-- Testcase 005: CREATE OR REPLACE FUNCTION atsort( a text[]) RETURNS text[] LANGUAGE sql IMMUTABLE STRICT AS $function$ select array(select unnest($1) order by 1) -$function$ - -; - - +$function$; create server localredis foreign data wrapper redis_fdw; @@ -61,7 +67,7 @@ $$; -- ok, empty, so now run the setup script -\! redis-cli < test/sql/redis_setup +\! redis-cli < test/redis_setup select * from db15 order by key; @@ -231,7 +237,7 @@ select * from db15_1key_zset_scores order by score desc; -- first clean the database again -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean -- singleton scalar table @@ -841,7 +847,7 @@ select * from db15_w_hash_kset; -- now clean up for the cursor tests -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean -- cursor tests @@ -891,5 +897,7 @@ select count(*) from db15bigkeysetscalar; -- all done, so now blow everything in the db away again -\! redis-cli < test/sql/redis_clean +\! redis-cli < test/redis_clean +DROP EXTENSION redis_fdw CASCADE; +DROP EXTENSION hstore;