Enable running all tests via "installcheck"

NOTE: also makes CDB_TableMetadata triggers still functional
      when user quota and varnish invalidation functions are missing
      from the database (currently installed by cartodb ruby)
This commit is contained in:
Sandro Santilli 2014-05-06 10:18:38 +02:00
parent 82c8259de6
commit 15740f2ef6
10 changed files with 81 additions and 19 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
cartodb--*.sql cartodb--*.sql
results/ results/
regression.* regression.*
expected/test
sql/test

View File

@ -9,9 +9,10 @@ CDBSCRIPTS = \
DATA_built = $(EXTENSION)--$(EXTVERSION).sql DATA_built = $(EXTENSION)--$(EXTVERSION).sql
DOCS = README.md DOCS = README.md
REGRESS_EXTENSION = test_ddl_triggers REGRESS_NEW = test_ddl_triggers
REGRESS_LEGACY = test/CDB_DigitSeparatorTest REGRESS_OLD = $(wildcard test/*.sql)
REGRESS = $(REGRESS_EXTENSION) REGRESS_LEGACY = $(REGRESS_OLD:.sql=)
REGRESS = test_setup $(REGRESS_NEW) $(REGRESS_LEGACY)
PG_CONFIG = pg_config PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs) PGXS := $(shell $(PG_CONFIG) --pgxs)
@ -24,3 +25,25 @@ $(EXTENSION)--$(EXTVERSION).sql: $(CDBSCRIPTS) cartodb_hooks.sql Makefile
-e 's/:DATABASE_USERNAME/cdb_org_admin/g' >> $@ -e 's/:DATABASE_USERNAME/cdb_org_admin/g' >> $@
echo "GRANT USAGE ON SCHEMA cartodb TO public;" >> $@ echo "GRANT USAGE ON SCHEMA cartodb TO public;" >> $@
cat cartodb_hooks.sql >> $@ cat cartodb_hooks.sql >> $@
legacy_regress: $(REGRESS_OLD) Makefile
mkdir -p sql/test/
mkdir -p expected/test/
for f in $(REGRESS_OLD); do \
tn=`basename $${f} .sql`; \
of=sql/test/$${tn}.sql; \
echo '\\set ECHO off' > $${of}; \
echo '\\a' >> $${of}; \
echo '\\t' >> $${of}; \
echo '\\set QUIET off' >> $${of}; \
cat $${f} | \
sed -e 's/\<public\./cartodb./g' >> $${of}; \
exp=expected/test/$${tn}.out; \
echo '\\set ECHO off' > $${exp}; \
cat test/$${tn}_expect >> $${exp}; \
done
legacy_tests: legacy_regress
installcheck: legacy_tests

View File

@ -1,8 +1,4 @@
CREATE EXTENSION postgis; \set VERBOSITY terse
CREATE EXTENSION schema_triggers;
CREATE EXTENSION cartodb;
set search_path to public,cartodb,schema_triggers;
--set client_min_messages to debug;
-- Create a stub cdb_invalidate_varnish function if not available -- Create a stub cdb_invalidate_varnish function if not available
--CREATE FUNCTION tmp() returns void AS $$ --CREATE FUNCTION tmp() returns void AS $$
DO $$ DO $$
@ -24,6 +20,11 @@ SET SESSION AUTHORIZATION 'cartodb_postgresql_unpriv_user';
-- CREATE TABLE -- CREATE TABLE
---------------------- ----------------------
select 1 as i INTO c.t3; select 1 as i INTO c.t3;
NOTICE: trigger "track_updates" for table "c.t3" does not exist, skipping
NOTICE: trigger "update_the_geom_webmercator_trigger" for table "c.t3" does not exist, skipping
NOTICE: trigger "update_updated_at_trigger" for table "c.t3" does not exist, skipping
NOTICE: trigger "test_quota" for table "c.t3" does not exist, skipping
NOTICE: trigger "test_quota_per_row" for table "c.t3" does not exist, skipping
select select
cartodb_id, created_at=updated_at as "c=u", cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s", NOW() - updated_at < '1 secs' as "u<1s",
@ -54,6 +55,15 @@ select pg_sleep(1);
(1 row) (1 row)
alter table c.t3 rename column the_geom_webmercator to webmerc; alter table c.t3 rename column the_geom_webmercator to webmerc;
NOTICE: Column cartodb_id already exists
NOTICE: Column created_at already exists
NOTICE: Column updated_at already exists
NOTICE: Column the_geom already exists
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
select select
cartodb_id, created_at=updated_at as "c=u", cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s", NOW() - updated_at < '1 secs' as "u<1s",
@ -81,6 +91,15 @@ select pg_sleep(1);
(1 row) (1 row)
alter table c.t3 rename column the_geom_webmercator to webmerc2; alter table c.t3 rename column the_geom_webmercator to webmerc2;
NOTICE: Column cartodb_id already exists
NOTICE: Column created_at already exists
NOTICE: Column updated_at already exists
NOTICE: Column the_geom already exists
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
select select
cartodb_id, created_at=updated_at as "c=u", cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s", NOW() - updated_at < '1 secs' as "u<1s",
@ -111,6 +130,15 @@ select pg_sleep(1);
(1 row) (1 row)
alter table c.t3 drop column the_geom_webmercator; alter table c.t3 drop column the_geom_webmercator;
NOTICE: Column cartodb_id already exists
NOTICE: Column created_at already exists
NOTICE: Column updated_at already exists
NOTICE: Column the_geom already exists
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
NOTICE: event trigger "cdb_on_drop_column" does not exist, skipping
NOTICE: event trigger "cdb_on_add_column" does not exist, skipping
select select
cartodb_id, created_at=updated_at as "c=u", cartodb_id, created_at=updated_at as "c=u",
NOW() - updated_at < '1 secs' as "u<1s", NOW() - updated_at < '1 secs' as "u<1s",
@ -166,6 +194,7 @@ FROM CDB_TableMetadata;
---------------------------- ----------------------------
RESET SESSION AUTHORIZATION; RESET SESSION AUTHORIZATION;
drop schema c cascade; drop schema c cascade;
NOTICE: drop cascades to table c.t3
select count(*) from CDB_TableMetadata; select count(*) from CDB_TableMetadata;
count count
------- -------

3
expected/test_setup.out Normal file
View File

@ -0,0 +1,3 @@
CREATE EXTENSION postgis;
CREATE EXTENSION schema_triggers;
CREATE EXTENSION cartodb;

View File

@ -35,7 +35,12 @@ BEGIN
IF dice < pbfact THEN IF dice < pbfact THEN
RAISE DEBUG 'Checking quota on table % (dice:%, needed:<%)', TG_RELID::text, dice, pbfact; RAISE DEBUG 'Checking quota on table % (dice:%, needed:<%)', TG_RELID::text, dice, pbfact;
BEGIN
qmax := public._CDB_UserQuotaInBytes(); qmax := public._CDB_UserQuotaInBytes();
EXCEPTION WHEN undefined_function THEN
RAISE WARNING 'Missing _CDB_UserQuotaInBytes(), assuming no quota';
RETURN NEW;
END;
SELECT CDB_UserDataSize() INTO quota; SELECT CDB_UserDataSize() INTO quota;
IF quota > qmax THEN IF quota > qmax THEN
RAISE EXCEPTION 'Quota exceeded by %KB', (quota-qmax)/1024; RAISE EXCEPTION 'Quota exceeded by %KB', (quota-qmax)/1024;

View File

@ -82,7 +82,11 @@ BEGIN
-- --
-- LISTEN cdb_tabledata_update; -- LISTEN cdb_tabledata_update;
-- --
BEGIN
PERFORM cdb_invalidate_varnish(tabname); PERFORM cdb_invalidate_varnish(tabname);
EXCEPTION WHEN undefined_function THEN
RAISE WARNING 'Missing cdb_invalidate_varnish()';
END;
RETURN NULL; RETURN NULL;
END; END;

View File

@ -22,7 +22,7 @@ AS $$
'spatial_ref_sys' 'spatial_ref_sys'
) )
), perms AS ( ), perms AS (
SELECT t, has_table_privilege('publicuser', 'public.'||t, 'SELECT') as p SELECT t, has_table_privilege('publicuser', t, 'SELECT') as p
FROM usertables FROM usertables
) )
SELECT t FROM perms SELECT t FROM perms

View File

@ -1 +0,0 @@
../test

View File

@ -1,10 +1,4 @@
CREATE EXTENSION postgis; \set VERBOSITY terse
CREATE EXTENSION schema_triggers;
CREATE EXTENSION cartodb;
set search_path to public,cartodb,schema_triggers;
--set client_min_messages to debug;
-- Create a stub cdb_invalidate_varnish function if not available -- Create a stub cdb_invalidate_varnish function if not available
--CREATE FUNCTION tmp() returns void AS $$ --CREATE FUNCTION tmp() returns void AS $$

3
sql/test_setup.sql Normal file
View File

@ -0,0 +1,3 @@
CREATE EXTENSION postgis;
CREATE EXTENSION schema_triggers;
CREATE EXTENSION cartodb;