-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
postgis: add tests with and without sfcgal
- Loading branch information
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
pkgs, | ||
makeTest, | ||
}: | ||
|
||
let | ||
inherit (pkgs) lib; | ||
|
||
# Test cases from https://www.postgis.net/workshops/postgis-intro/geometries.html | ||
# This should be enough to check if the extension is correctly loaded | ||
test-sql = pkgs.writeText "postgresql-test" '' | ||
\set ON_ERROR_STOP on | ||
CREATE EXTENSION postgis; | ||
CREATE TABLE geometries ( | ||
name varchar, | ||
geom geometry NOT NULL | ||
); | ||
INSERT INTO geometries VALUES | ||
('Point', 'POINT(0 0)'), | ||
('Linestring', 'LINESTRING(0 0, 1 1, 2 1, 2 2)'), | ||
('Polygon', 'POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'), | ||
('PolygonWithHole', 'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))'), | ||
('Collection', 'GEOMETRYCOLLECTION(POINT(2 0),POLYGON((0 0, 1 0, 1 1, 0 1, 0 0)))'); | ||
''; | ||
|
||
makeTestFor = | ||
package: | ||
makeTest { | ||
name = "postgis-${package.name}"; | ||
meta = { | ||
maintainers = lib.teams.geospatial.members; | ||
}; | ||
|
||
nodes.machine = | ||
{ ... }: | ||
{ | ||
services.postgresql = { | ||
inherit package; | ||
enable = true; | ||
enableJIT = lib.hasInfix "-jit-" package.name; | ||
extensions = | ||
ps: with ps; [ | ||
postgis | ||
]; | ||
}; | ||
}; | ||
|
||
testScript = | ||
{ nodes, ... }: | ||
let | ||
inherit (nodes.machine.services.postgresql.package.pkgs) postgis; | ||
in | ||
'' | ||
def check_count(statement, lines): | ||
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format( | ||
statement, lines | ||
) | ||
machine.start() | ||
machine.wait_for_unit("postgresql") | ||
with subtest("Postgresql with extension postgis is available just after unit start"): | ||
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'postgis' AND default_version = '${postgis.version}';", 1)) | ||
machine.succeed("sudo -u postgres psql -f ${test-sql}") | ||
machine.succeed(check_count("SELECT name, st_astext(geom) FROM geometries WHERE name like 'Polygon%';", 2)) | ||
machine.shutdown() | ||
''; | ||
}; | ||
in | ||
lib.recurseIntoAttrs ( | ||
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( | ||
lib.filterAttrs (_: p: !p.pkgs.postgis.meta.broken) pkgs.postgresqlVersions | ||
) | ||
// { | ||
passthru.override = p: makeTestFor p; | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
pkgs, | ||
makeTest, | ||
}: | ||
|
||
let | ||
inherit (pkgs) lib; | ||
|
||
# Test cases from https://www.postgis.net/workshops/postgis-intro/geometries.html | ||
# This should be enough to check if the extension is correctly loaded | ||
test-sql = pkgs.writeText "postgresql-test" '' | ||
\set ON_ERROR_STOP on | ||
CREATE EXTENSION postgis_sfcgal cascade; | ||
CREATE TABLE geometries ( | ||
name varchar, | ||
geom geometry(PolygonZ) NOT NULL | ||
); | ||
INSERT INTO geometries(name, geom) VALUES | ||
('planar geom', 'PolygonZ((1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0))'), | ||
('nonplanar geom', 'PolygonZ((1 1 1, 1 2 -1, 2 2 2, 2 1 0, 1 1 1))'); | ||
''; | ||
|
||
makeTestFor = | ||
package: | ||
makeTest { | ||
name = "postgis_sfcgal-${package.name}"; | ||
meta = { | ||
maintainers = lib.teams.geospatial.members; | ||
}; | ||
|
||
nodes.machine = | ||
{ ... }: | ||
{ | ||
services.postgresql = { | ||
inherit package; | ||
enable = true; | ||
enableJIT = lib.hasInfix "-jit-" package.name; | ||
extensions = | ||
ps: with ps; [ | ||
(postgis.override ({ withSfcgal = true; })) | ||
]; | ||
}; | ||
}; | ||
|
||
testScript = | ||
{ nodes, ... }: | ||
let | ||
inherit (nodes.machine.services.postgresql.package.pkgs) postgis; | ||
in | ||
'' | ||
def check_count(statement, lines): | ||
return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format( | ||
statement, lines | ||
) | ||
def check_return(statement, expected): | ||
return 'test $(sudo -u postgres psql -tAc "{}") = {}'.format(statement, expected) | ||
machine.start() | ||
machine.wait_for_unit("postgresql") | ||
with subtest("Postgresql with extension postgis is available just after unit start"): | ||
machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'postgis_sfcgal' AND default_version = '${postgis.version}';", 1)) | ||
machine.succeed("sudo -u postgres psql -f ${test-sql}") | ||
machine.succeed(check_return("select postgis_sfcgal_version()", "${pkgs.sfcgal.version}")) | ||
machine.succeed(check_count("SELECT name from geometries where cg_isplanar(geom)", 1)) | ||
machine.shutdown() | ||
''; | ||
}; | ||
in | ||
lib.recurseIntoAttrs ( | ||
lib.concatMapAttrs (n: p: { ${n} = makeTestFor p; }) ( | ||
lib.filterAttrs (_: p: !p.pkgs.postgis.meta.broken) pkgs.postgresqlVersions | ||
) | ||
// { | ||
passthru.override = p: makeTestFor p; | ||
} | ||
) |