Add regress target

Runs the regress tests without installing the extension
This commit is contained in:
Raul Marin 2019-10-28 15:12:04 +01:00
parent a25efc3fc5
commit 8ff0ad74af
4 changed files with 20 additions and 60 deletions

View File

@ -127,7 +127,7 @@ EXTRA_CLEAN = cartodb_version.sql
DOCS = README.md DOCS = README.md
REGRESS_OLD = $(wildcard test/*.sql) REGRESS_OLD = $(wildcard test/*.sql)
REGRESS_LEGACY = $(REGRESS_OLD:.sql=) REGRESS_LEGACY = $(REGRESS_OLD:.sql=)
REGRESS = test_setup $(REGRESS_LEGACY) REGRESS = test/test_setup $(REGRESS_LEGACY)
PG_CONFIG = pg_config PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs) PGXS := $(shell $(PG_CONFIG) --pgxs)
@ -171,6 +171,10 @@ legacy_regress: $(REGRESS_OLD) Makefile
mkdir -p sql/test/ mkdir -p sql/test/
mkdir -p expected/test/ mkdir -p expected/test/
mkdir -p results/test/ mkdir -p results/test/
cat sql/test_setup.sql | \
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/plpythonu/$(PLPYTHONU)/g' \
> sql/test/test_setup.sql
cp sql/test_setup_expect expected/test/test_setup.out
for f in $(REGRESS_OLD); do \ for f in $(REGRESS_OLD); do \
tn=`basename $${f} .sql`; \ tn=`basename $${f} .sql`; \
of=sql/test/$${tn}.sql; \ of=sql/test/$${tn}.sql; \
@ -179,7 +183,7 @@ legacy_regress: $(REGRESS_OLD) Makefile
echo '\t' >> $${of}; \ echo '\t' >> $${of}; \
echo '\set QUIET off' >> $${of}; \ echo '\set QUIET off' >> $${of}; \
cat $${f} | \ cat $${f} | \
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" >> $${of}; \ $(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/plpythonu/$(PLPYTHONU)/g' >> $${of}; \
exp=expected/test/$${tn}.out; \ exp=expected/test/$${tn}.out; \
echo '\set ECHO none' > $${exp}; \ echo '\set ECHO none' > $${exp}; \
cat test/$${tn}_expect >> $${exp}; \ cat test/$${tn}_expect >> $${exp}; \
@ -191,7 +195,11 @@ test_organization:
test_extension_new: test_extension_new:
bash test/extension/test.sh bash test/extension/test.sh
legacy_tests: legacy_regress legacy_tests: legacy_regress $(EXTENSION)--unpackaged--$(EXTVERSION).sql
PGREGRESS := $(shell dirname `$(PG_CONFIG) --pgxs`)/../../src/test/regress/pg_regress
regress: legacy_tests
$(PGREGRESS) --inputdir=./ --bindir='/usr/bin' --dbname=contrib_regression $(REGRESS)
installcheck: legacy_tests test_extension_new test_organization installcheck: legacy_tests test_extension_new test_organization

View File

@ -1,8 +1,14 @@
\set ECHO none
\set QUIET on
SET client_min_messages TO error; SET client_min_messages TO error;
CREATE EXTENSION cartodb CASCADE; CREATE EXTENSION postgis;
CREATE EXTENSION plpythonu;
CREATE SCHEMA cartodb;
\i 'cartodb--unpackaged--@@VERSION@@.sql'
CREATE FUNCTION public.cdb_invalidate_varnish(table_name text) CREATE FUNCTION public.cdb_invalidate_varnish(table_name text)
RETURNS void AS $$ RETURNS void AS $$
BEGIN BEGIN
RAISE NOTICE 'cdb_invalidate_varnish(%) called', table_name; RAISE NOTICE 'cdb_invalidate_varnish(%) called', table_name;
END; END;
$$ LANGUAGE 'plpgsql'; $$ LANGUAGE 'plpgsql';
\set QUIET off

1
sql/test_setup_expect Normal file
View File

@ -0,0 +1 @@
\set ECHO none

View File

@ -20,59 +20,4 @@ cat ${input} |
cat >> ${output} cat >> ${output}
# Upgrade all functions # Upgrade all functions
cat ${input} | grep -v 'duplicated extension$' | grep -v '\quit$' >> ${output} cat ${input} | grep -v 'duplicated extension$' | grep -v '\quit$' | grep -v 'pg_extension_config_dump' >> ${output}
# Migrate CDB_TableMetadata
cat >> ${output} <<'EOF'
ALTER TABLE cartodb.CDB_TableMetadata DISABLE TRIGGER ALL;
INSERT INTO cartodb.CDB_TableMetadata SELECT * FROM public.CDB_TableMetadata;
ALTER TABLE cartodb.CDB_TableMetadata ENABLE TRIGGER ALL;
DROP TABLE public.CDB_TableMetadata;
-- Set user quota
-- NOTE: will fail if user quota wasn't set at database level, see
-- http://github.com/CartoDB/cartodb-postgresql/issues/18
DO $$
DECLARE
qmax int8;
BEGIN
BEGIN
qmax := public._CDB_UserQuotaInBytes();
EXCEPTION WHEN undefined_function THEN
RAISE EXCEPTION 'Please set user quota before switching to cartodb extension';
END;
PERFORM cartodb.CDB_SetUserQuotaInBytes(qmax);
DROP FUNCTION public._CDB_UserQuotaInBytes();
END;
$$ LANGUAGE 'plpgsql';
EOF
## Cartodbfy tables with a trigger using 'CDB_CheckQuota' or
## 'CDB_TableMetadata_Trigger' from the 'public' schema
#cat >> ${output} <<'EOF'
#select cartodb.CDB_CartodbfyTable(relname::regclass) from (
# -- names of tables using public.CDB_CheckQuota or
# -- public.CDB_TableMetadata_Trigger in their triggers
# SELECT distinct c.relname
# FROM
# pg_trigger t,
# pg_class c,
# pg_proc p,
# pg_namespace n
# WHERE
# n.nspname = 'public' AND
# p.pronamespace = n.oid AND
# p.proname IN ( 'cdb_checkquota', 'cdb_tablemetadata_trigger' ) AND
# t.tgrelid = c.oid AND
# p.oid = t.tgfoid
#) as foo;
#EOF
## Drop any leftover function from public schema (there should be none)
#cat ${input} |
# grep '^ *CREATE OR REPLACE FUNCTION' |
# grep -v ' cartodb\.' | # should only match DDL hooks
# sed 's/).*$/);/' |
# sed 's/DEFAULT [^ ,)]*//g' |
# sed 's/CREATE OR REPLACE FUNCTION /DROP FUNCTION IF EXISTS public./' |
# cat >> ${output}