Skip to content

Commit

Permalink
fix(tests): remove deprecated pgtap function 'subtest'
Browse files Browse the repository at this point in the history
  • Loading branch information
danimarinBG committed Aug 19, 2024
1 parent d69d8c3 commit 0fc7f47
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 318 deletions.
178 changes: 65 additions & 113 deletions test/upsert/ud/test_cat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,127 +7,79 @@ BEGIN;

SET search_path = "SCHEMA_NAME", public, pg_catalog;

SELECT plan(3);
SELECT plan(16);

-- Subtest 1: Testing cat_work operations | insert/update/delete
SELECT subtest('cat_work operations', $$
BEGIN;
SELECT plan(4);

-- 1. INSERT
INSERT INTO cat_work (id, descript, link, workid_key1, workid_key2, builtdate, workcost, active)
VALUES('work5', 'Description work5', NULL, NULL, NULL, '2024-08-19', NULL, true);
SELECT is((SELECT count(*)::integer FROM cat_work WHERE id = 'work5'), 1, 'INSERT: cat_work "work5" was inserted');
RAISE NOTICE 'Subtest 1: Testing cat_work operations | insert/update/delete';
INSERT INTO cat_work (id, descript, link, workid_key1, workid_key2, builtdate, workcost, active)
VALUES('work5', 'Description work5', NULL, NULL, NULL, '2024-08-19', NULL, true);
SELECT is((SELECT count(*)::integer FROM cat_work WHERE id = 'work5'), 1, 'INSERT: cat_work "work5" was inserted');

-- 2. UPDATE
UPDATE cat_work SET descript = 'updated test' WHERE id = 'work5';
SELECT is((SELECT descript FROM cat_work WHERE id = 'work5'), 'updated test', 'UPDATE: descript was updated to "updated test"');
UPDATE cat_work SET descript = 'updated test' WHERE id = 'work5';
SELECT is((SELECT descript FROM cat_work WHERE id = 'work5'), 'updated test', 'UPDATE: descript was updated to "updated test"');

-- 3. UPSERT
INSERT INTO cat_work (id, descript, link, workid_key1, workid_key2, builtdate, workcost, active)
VALUES('work5', 'upsert test', NULL, NULL, NULL, '2024-08-19', NULL, true)
ON CONFLICT (id) DO UPDATE SET descript = EXCLUDED.descript;
SELECT is((SELECT descript FROM cat_work WHERE id = 'work5'), 'upsert test', 'UPSERT: descript was updated to "upsert test" using ON CONFLICT');
INSERT INTO cat_work (id, descript, link, workid_key1, workid_key2, builtdate, workcost, active)
VALUES('work5', 'upsert test', NULL, NULL, NULL, '2024-08-19', NULL, true)
ON CONFLICT (id) DO UPDATE SET descript = EXCLUDED.descript;
SELECT is((SELECT descript FROM cat_work WHERE id = 'work5'), 'upsert test', 'UPSERT: descript was updated to "upsert test" using ON CONFLICT');

-- 4. DELETE
DELETE FROM cat_work WHERE id = 'work5';
SELECT is((SELECT count(*)::integer FROM cat_work WHERE id = 'work5'), 0, 'DELETE: cat_work "work5" was deleted');
DELETE FROM cat_work WHERE id = 'work5';
SELECT is((SELECT count(*)::integer FROM cat_work WHERE id = 'work5'), 0, 'DELETE: cat_work "work5" was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

-- Subtest 2: Testing cat_feature_node operations | insert/update/delete (junction, circ_manhole, sewer_storage)
SELECT subtest('cat_feature_node operations', $$
BEGIN;
SELECT plan(3);

-- JUNCTION
SELECT subtest('cat_feature_node junction operations', $$
BEGIN;
-- 1. INSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('JUNCTION2', 'JUNCTION', 'JUNCTION', 2, true, true, true, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'JUNCTION2'), 1, 'INSERT: cat_feature_node "JUNCTION2" was inserted');

-- 2. UPDATE
UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'JUNCTION2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'JUNCTION2'), 1, 'UPDATE: num_arcs was updated to 1');

-- 3. UPSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('JUNCTION2', 'JUNCTION', 'JUNCTION', 3, true, true, true, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'JUNCTION2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

-- 4. DELETE
DELETE FROM cat_feature_node WHERE id = 'JUNCTION2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'JUNCTION2'), 0, 'DELETE: cat_feature_node "JUNCTION2" was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

-- CIRC_MANHOLE
SELECT subtest('cat_feature_node circ_manhole operations', $$
BEGIN;
-- 1. INSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('CIRC_MANHOLE2', 'MANHOLE', 'JUNCTION', 2, true, true, true, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 1, 'INSERT: cat_feature_node "CIRC_MANHOLE2" was inserted');

-- 2. UPDATE
UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'CIRC_MANHOLE2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 1, 'UPDATE: num_arcs was updated to 1');

-- 3. UPSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('CIRC_MANHOLE2', 'MANHOLE', 'JUNCTION', 3, true, true, true, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

-- 4. DELETE
DELETE FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 0, 'DELETE: cat_feature_node "CIRC_MANHOLE2" was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

-- SEWER_STORAGE
SELECT subtest('cat_feature_node sewer_storage operations', $$
BEGIN;
-- 1. INSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('SEWER_STORAGE2', 'SEWER_STORAGE', 'SEWER_STORAGE', 2, true, true, false, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 1, 'INSERT: cat_feature_node "SEWER_STORAGE2" was inserted');

-- 2. UPDATE
UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'SEWER_STORAGE2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 1, 'UPDATE: num_arcs was updated to 1');

-- 3. UPSERT
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('SEWER_STORAGE2', 'SEWER_STORAGE', 'SEWER_STORAGE', 3, true, true, false, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

-- 4. DELETE
DELETE FROM cat_feature_node WHERE id = 'SEWER_STORAGE2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 0, 'DELETE: cat_feature_node "SEWER_STORAGE2" was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

SELECT * FROM finish();
ROLLBACK;
END;
$$);
RAISE NOTICE 'Subtest 2: Testing cat_feature_node operations | insert/update/delete';
-- JUNCTION
RAISE NOTICE 'Subtest 2.1: Testing cat_feature_node JUNCTION';
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('JUNCTION2', 'JUNCTION', 'JUNCTION', 2, true, true, true, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'JUNCTION2'), 1, 'INSERT: cat_feature_node "JUNCTION2" was inserted');

UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'JUNCTION2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'JUNCTION2'), 1, 'UPDATE: num_arcs was updated to 1');

INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('JUNCTION2', 'JUNCTION', 'JUNCTION', 3, true, true, true, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'JUNCTION2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

DELETE FROM cat_feature_node WHERE id = 'JUNCTION2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'JUNCTION2'), 0, 'DELETE: cat_feature_node "JUNCTION2" was deleted');

-- CIRC_MANHOLE
RAISE NOTICE 'Subtest 2.2: Testing cat_feature_node CIRC_MANHOLE';
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('CIRC_MANHOLE2', 'MANHOLE', 'JUNCTION', 2, true, true, true, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 1, 'INSERT: cat_feature_node "CIRC_MANHOLE2" was inserted');

UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'CIRC_MANHOLE2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 1, 'UPDATE: num_arcs was updated to 1');

INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('CIRC_MANHOLE2', 'MANHOLE', 'JUNCTION', 3, true, true, true, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

DELETE FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'CIRC_MANHOLE2'), 0, 'DELETE: cat_feature_node "CIRC_MANHOLE2" was deleted');

-- SEWER_STORAGE
RAISE NOTICE 'Subtest 2.3: Testing cat_feature_node SEWER_STORAGE';
INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('SEWER_STORAGE2', 'SEWER_STORAGE', 'SEWER_STORAGE', 2, true, true, false, 0, '{"activated":false,"value":1}'::json);
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 1, 'INSERT: cat_feature_node "SEWER_STORAGE2" was inserted');

UPDATE cat_feature_node SET num_arcs = 1 WHERE id = 'SEWER_STORAGE2';
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 1, 'UPDATE: num_arcs was updated to 1');

INSERT INTO cat_feature_node (id, "type", epa_default, num_arcs, choose_hemisphere, isarcdivide, isprofilesurface, isexitupperintro, double_geom)
VALUES('SEWER_STORAGE2', 'SEWER_STORAGE', 'SEWER_STORAGE', 3, true, true, false, 0, '{"activated":false,"value":1}'::json);
ON CONFLICT (id) DO UPDATE SET num_arcs = EXCLUDED.num_arcs;
SELECT is((SELECT num_arcs FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 3, 'UPSERT: num_arcs was updated to 3 using ON CONFLICT');

DELETE FROM cat_feature_node WHERE id = 'SEWER_STORAGE2';
SELECT is((SELECT count(*)::integer FROM cat_feature_node WHERE id = 'SEWER_STORAGE2'), 0, 'DELETE: cat_feature_node "SEWER_STORAGE2" was deleted');


-- Subtest 3: Testing cat_feature_arc operations | insert/update/delete (conduit, siphon, waccel, pump_pipe)

Expand Down
70 changes: 24 additions & 46 deletions test/upsert/ud/test_doc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,42 @@ BEGIN;

SET search_path = "SCHEMA_NAME", public, pg_catalog;

SELECT plan(2);
SELECT plan(8);

-- Subtest 1: Testing doc_type operations
SELECT subtest('doc_type operations', $$
BEGIN;
SELECT plan(4);

-- 1. INSERT
INSERT INTO doc_type (id, comment) VALUES ('AS_BUILT2', 'test');
SELECT is((SELECT count(*)::integer FROM doc_type WHERE id = 'AS_BUILT2'), 1, 'INSERT: doc_type "AS_BUILT2" was inserted');
RAISE NOTICE 'Subtest 1: Testing doc_type operations';
INSERT INTO doc_type (id, comment) VALUES ('AS_BUILT2', 'test');
SELECT is((SELECT count(*)::integer FROM doc_type WHERE id = 'AS_BUILT2'), 1, 'INSERT: doc_type "AS_BUILT2" was inserted');

-- 2. UPDATE
UPDATE doc_type SET comment = 'updated test' WHERE id = 'AS_BUILT2';
SELECT is((SELECT comment FROM doc_type WHERE id = 'AS_BUILT2'), 'updated test', 'UPDATE: Comment was updated to "updated test"');
UPDATE doc_type SET comment = 'updated test' WHERE id = 'AS_BUILT2';
SELECT is((SELECT comment FROM doc_type WHERE id = 'AS_BUILT2'), 'updated test', 'UPDATE: Comment was updated to "updated test"');

-- 3. UPSERT
INSERT INTO doc_type (id, comment)
VALUES ('AS_BUILT2', 'upsert test')
ON CONFLICT (id) DO UPDATE SET comment = EXCLUDED.comment;
SELECT is((SELECT comment FROM doc_type WHERE id = 'AS_BUILT2'), 'upsert test', 'UPSERT: Comment was updated to "upsert test" using ON CONFLICT');
INSERT INTO doc_type (id, comment)
VALUES ('AS_BUILT2', 'upsert test')
ON CONFLICT (id) DO UPDATE SET comment = EXCLUDED.comment;
SELECT is((SELECT comment FROM doc_type WHERE id = 'AS_BUILT2'), 'upsert test', 'UPSERT: Comment was updated to "upsert test" using ON CONFLICT');

-- 4. DELETE
DELETE FROM doc_type WHERE id = 'AS_BUILT2';
SELECT is((SELECT count(*)::integer FROM doc_type WHERE id = 'AS_BUILT2'), 0, 'DELETE: doc_type AS_BUILT2 was deleted');
DELETE FROM doc_type WHERE id = 'AS_BUILT2';
SELECT is((SELECT count(*)::integer FROM doc_type WHERE id = 'AS_BUILT2'), 0, 'DELETE: doc_type AS_BUILT2 was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

-- Subtest 2: Testing doc operations
SELECT subtest('doc operations', $$
BEGIN;
SELECT plan(4);

-- 1. INSERT
INSERT INTO doc (id, doc_type, "path", observ, "date", user_name, tstamp, the_geom, "name")
VALUES('Demo document 4', 'OTHER', 'https://bgeo.es', NULL, '2024-08-19 12:06:28.330', 'postgres', '2024-08-19 12:06:28.330', NULL, NULL);
SELECT is((SELECT count(*)::integer FROM doc WHERE id = 'Demo document 4'), 1, 'INSERT: doc "Demo document 4" was inserted');
RAISE NOTICE 'Subtest 2: Testing doc operations'
INSERT INTO doc (id, doc_type, "path", observ, "date", user_name, tstamp, the_geom, "name")
VALUES('Demo document 4', 'OTHER', 'https://bgeo.es', NULL, '2024-08-19 12:06:28.330', 'postgres', '2024-08-19 12:06:28.330', NULL, NULL);
SELECT is((SELECT count(*)::integer FROM doc WHERE id = 'Demo document 4'), 1, 'INSERT: doc "Demo document 4" was inserted');

-- 2. UPDATE
UPDATE doc SET observ = 'updated test' WHERE id = 'Demo document 4';
SELECT is((SELECT observ FROM doc WHERE id = 'Demo document 4'), 'updated test', 'UPDATE: observ was updated to "updated test"');
UPDATE doc SET observ = 'updated test' WHERE id = 'Demo document 4';
SELECT is((SELECT observ FROM doc WHERE id = 'Demo document 4'), 'updated test', 'UPDATE: observ was updated to "updated test"');

-- 3. UPSERT
INSERT INTO doc (id, doc_type, "path", observ, "date", user_name, tstamp, the_geom, "name")
VALUES('Demo document 4', 'OTHER', 'https://bgeo.es', 'upsert test', '2024-08-19 12:06:28.330', 'postgres', '2024-08-19 12:06:28.330', NULL, NULL)
ON CONFLICT (id) DO UPDATE SET observ = EXCLUDED.observ;
SELECT is((SELECT observ FROM doc WHERE id = 'Demo document 4'), 'upsert test', 'UPSERT: observ was updated to "upsert test" using ON CONFLICT');
INSERT INTO doc (id, doc_type, "path", observ, "date", user_name, tstamp, the_geom, "name")
VALUES('Demo document 4', 'OTHER', 'https://bgeo.es', 'upsert test', '2024-08-19 12:06:28.330', 'postgres', '2024-08-19 12:06:28.330', NULL, NULL)
ON CONFLICT (id) DO UPDATE SET observ = EXCLUDED.observ;
SELECT is((SELECT observ FROM doc WHERE id = 'Demo document 4'), 'upsert test', 'UPSERT: observ was updated to "upsert test" using ON CONFLICT');

-- 4. DELETE
DELETE FROM doc WHERE id = 'Demo document 4';
SELECT is((SELECT count(*)::integer FROM doc WHERE id = 'Demo document 4'), 0, 'DELETE: doc "Demo document 4" was deleted');
DELETE FROM doc WHERE id = 'Demo document 4';
SELECT is((SELECT count(*)::integer FROM doc WHERE id = 'Demo document 4'), 0, 'DELETE: doc "Demo document 4" was deleted');

SELECT * FROM finish();
ROLLBACK;
END;
$$);

SELECT * FROM finish();

Expand Down
Loading

0 comments on commit 0fc7f47

Please sign in to comment.