Merge branch 'master' of https://github.com/CartoDB/cartodb-postgresql into CDB-3094
This commit is contained in:
@@ -146,28 +146,82 @@ DROP TABLE t;
|
||||
CREATE TABLE t AS SELECT ST_SetSRID(ST_MakePoint(-1,-1),4326) as the_geom
|
||||
UNION ALL SELECT ST_SetSRID(ST_MakePoint(0,0),3857);
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'mixed-srid the_geom');
|
||||
SELECT 'extent',ST_Extent(the_geom) FROM t;
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with wrong srid-constrained the_geom values
|
||||
CREATE TABLE t AS SELECT 'SRID=3857;LINESTRING(222638.981586547 222684.208505545, 111319.490793274 111325.142866385)'::geometry(geometry,3857) as the_geom;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'wrong srid-constrained the_geom');
|
||||
SELECT 'extent',ST_Extent(the_geom),ST_Extent(ST_SnapToGrid(the_geom_webmercator,1)) FROM t;
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)),ST_Extent(ST_SnapToGrid(the_geom_webmercator,1)) FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with wrong srid-constrained the_geom_webmercator values (and no the_geom!)
|
||||
CREATE TABLE t AS SELECT 'SRID=4326;LINESTRING(1 1,2 2)'::geometry(geometry,4326) as the_geom_webmercator;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'wrong srid-constrained the_geom_webmercator');
|
||||
-- expect the_geom to be populated from the_geom_webmercator
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.1)) FROM t;
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing triggered the_geom
|
||||
CREATE TABLE t AS SELECT 'SRID=4326;LINESTRING(1 1,2 2)'::geometry(geometry) as the_geom;
|
||||
CREATE TRIGGER update_the_geom_webmercator_trigger BEFORE UPDATE OF the_geom ON t
|
||||
FOR EACH ROW EXECUTE PROCEDURE public._CDB_update_the_geom_webmercator();
|
||||
FOR EACH ROW EXECUTE PROCEDURE _CDB_update_the_geom_webmercator();
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'trigger-protected the_geom');
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.1)) FROM t;
|
||||
SELECT 'extent',ST_Extent(ST_SnapToGrid(the_geom,0.2)) FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing updated_at and created_at fields ot type text
|
||||
CREATE TABLE t AS SELECT NOW()::text as created_at,
|
||||
NOW()::text as updated_at,
|
||||
NOW() as reftime;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'text timestamps');
|
||||
SELECT extract(secs from reftime-created_at),
|
||||
extract(secs from reftime-updated_at) FROM t;
|
||||
CREATE VIEW v AS SELECT * FROM t;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'cartodbfied with view');
|
||||
DROP VIEW v;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type text
|
||||
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
||||
select cartodb_id/2 FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type text not casting
|
||||
CREATE TABLE t AS SELECT 'nan' as cartodb_id;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'uncasting text cartodb_id');
|
||||
select cartodb_id,_cartodb_id0 FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id field of type int4 not sequenced
|
||||
CREATE TABLE t AS SELECT 1::int4 as cartodb_id;
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'unsequenced cartodb_id');
|
||||
select cartodb_id FROM t;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing cartodb_id serial primary key
|
||||
CREATE TABLE t ( cartodb_id serial primary key );
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'cartodb_id serial primary key');
|
||||
SELECT c.conname, a.attname FROM pg_constraint c, pg_attribute a
|
||||
WHERE c.conrelid = 't'::regclass and a.attrelid = c.conrelid
|
||||
AND c.conkey[1] = a.attnum AND NOT a.attisdropped;
|
||||
DROP TABLE t;
|
||||
|
||||
-- table with existing the_geom and created_at and containing null values
|
||||
-- Really, a test for surviving an longstanding PostgreSQL bug:
|
||||
-- http://www.postgresql.org/message-id/20140530143150.GA11051@localhost
|
||||
CREATE TABLE t (
|
||||
the_geom geometry(Geometry,4326),
|
||||
created_at timestamptz,
|
||||
updated_at timestamptz
|
||||
);
|
||||
COPY t (the_geom, created_at, updated_at) FROM stdin;
|
||||
0106000020E610000001000000010300000001000000050000009EB8244146435BC017B65E062AD343409EB8244146435BC0F51AF6E2708044400B99891683765AC0F51AF6E2708044400B99891683765AC017B65E062AD343409EB8244146435BC017B65E062AD34340 2012-06-06 21:59:08 2013-06-10 20:17:20
|
||||
0106000020E61000000100000001030000000100000005000000DA7763431A1A5CC0FBCEE869313C3A40DA7763431A1A5CC09C1B8F55BC494440F9F4A9C7993356C09C1B8F55BC494440F9F4A9C7993356C0FBCEE869313C3A40DA7763431A1A5CC0FBCEE869313C3A40 2012-06-06 21:59:08 2013-06-10 20:17:20
|
||||
\N \N \N
|
||||
\.
|
||||
SELECT CDB_CartodbfyTableCheck('t', 'null geom and timestamp values');
|
||||
DROP TABLE t;
|
||||
|
||||
-- TODO: table with existing custom-triggered the_geom
|
||||
|
||||
@@ -25,5 +25,31 @@ CREATE TRIGGER
|
||||
trigger-protected the_geom cartodbfied fine
|
||||
extent|BOX(1 1,2 2)
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
text timestamps cartodbfied fine
|
||||
0|0
|
||||
CREATE VIEW
|
||||
cartodbfied with view cartodbfied fine
|
||||
DROP VIEW
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
text cartodb_id cartodbfied fine
|
||||
5
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
uncasting text cartodb_id cartodbfied fine
|
||||
1|nan
|
||||
DROP TABLE
|
||||
SELECT 1
|
||||
unsequenced cartodb_id cartodbfied fine
|
||||
1
|
||||
DROP TABLE
|
||||
CREATE TABLE
|
||||
cartodb_id serial primary key cartodbfied fine
|
||||
t_pkey|cartodb_id
|
||||
DROP TABLE
|
||||
CREATE TABLE
|
||||
null geom and timestamp values cartodbfied fine
|
||||
DROP TABLE
|
||||
DROP FUNCTION
|
||||
DROP FUNCTION
|
||||
|
||||
@@ -26,3 +26,38 @@ INSER INTO "my''""t" values ('''','""'';;');
|
||||
SELECT $qu;oted$ hi $qu;oted$;
|
||||
$the_param$) as statement )
|
||||
SELECT '5', row_number() over (), statement FROM q;
|
||||
|
||||
WITH q AS ( SELECT CDB_QueryStatements($the_param$
|
||||
SELECT
|
||||
1 ; SELECT
|
||||
2
|
||||
$the_param$) as statement )
|
||||
SELECT '6', row_number() over (), statement FROM q;
|
||||
|
||||
-- This is an insane input, illegal sql
|
||||
-- we are really only testing that it does not
|
||||
-- take forever to process..
|
||||
-- The actual result is not correct, so if the function
|
||||
-- ever gets fixed check if it's better
|
||||
WITH q AS ( SELECT CDB_QueryStatements($the_param$
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/a
|
||||
$b$
|
||||
$c$d
|
||||
;
|
||||
$the_param$) as statement )
|
||||
SELECT '7', row_number() over (), statement FROM q;
|
||||
|
||||
|
||||
WITH q AS ( SELECT CDB_QueryStatements($the_param$
|
||||
SELECT $quoted$ hi
|
||||
$quoted$;
|
||||
$the_param$) as statement )
|
||||
SELECT '8', row_number() over (), statement FROM q;
|
||||
|
||||
@@ -7,3 +7,13 @@
|
||||
4|4|SELECT 5
|
||||
5|1|INSER INTO "my''""t" values ('''','""'';;')
|
||||
5|2|SELECT $qu;oted$ hi $qu;oted$
|
||||
6|1|SELECT
|
||||
1
|
||||
6|2|SELECT
|
||||
2
|
||||
7|1|/a
|
||||
7|2|b
|
||||
7|3|c
|
||||
7|4|d
|
||||
8|1|SELECT $quoted$ hi
|
||||
$quoted$
|
||||
|
||||
15
test/README
Normal file
15
test/README
Normal file
@@ -0,0 +1,15 @@
|
||||
Adding tests consists in adding 2 files in this directory: one file
|
||||
containing the sql code and another containing the expected output.
|
||||
|
||||
Example, to add a test for CDB_Something function, you'd add:
|
||||
|
||||
- CDB_SomethingTest.sql
|
||||
- CDB_SomethingTest_expect
|
||||
|
||||
To easy the generation of the expected file you can initially omit it,
|
||||
then run "make -C .. installcheck" from the top-level dir and copy
|
||||
../results/test/CDB_SomethingTest.out to CDB_SomethingTest_expect chopping
|
||||
off the first line:
|
||||
|
||||
make -C .. installcheck
|
||||
tail -n +2 ../results/test/CDB_SomethingTest.out > CDB_SomethingTest_expect
|
||||
Reference in New Issue
Block a user