Skip to content

Commit 9c589e4

Browse files
committed
test: add postgis specfic tests
Signed-off-by: Niccolò Fei <[email protected]>
1 parent 5e4293a commit 9c589e4

File tree

9 files changed

+141
-10
lines changed

9 files changed

+141
-10
lines changed

postgis/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ RUN mkdir -p /system /licenses && \
4545
for lib in $(find /system -maxdepth 1 -type f -name '*.so*'); do \
4646
# Get the name of the pkg that installed the library
4747
pkg=$(dpkg -S "$(basename "$lib")" | grep -v "diversion by" | awk -F: '/:/{print $1; exit}'); \
48-
echo "$lib: $pkg"; \
4948
[ -z "$pkg" ] && continue; \
5049
mkdir -p "/licenses/$pkg" && cp -a "/usr/share/doc/$pkg/copyright" "/licenses/$pkg/copyright"; \
5150
done

postgis/README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
This image provides a convenient way to deploy and manage `PostGIS` with
66
[CloudNativePG](https://cloudnative-pg.io/).
7+
It also packages [pgRouting](https://github.com/pgRouting/pgrouting).
78

89
## Usage
910

@@ -50,21 +51,14 @@ spec:
5051
name: cluster-postgis
5152
extensions:
5253
- name: postgis
53-
ensure: present
5454
- name: postgis_raster
55-
ensure: present
5655
- name: postgis_sfcgal
57-
ensure: present
5856
- name: fuzzystrmatch
59-
ensure: present
6057
- name: address_standardizer
61-
ensure: present
6258
- name: address_standardizer_data_us
63-
ensure: present
6459
- name: postgis_tiger_geocoder
65-
ensure: present
6660
- name: postgis_topology
67-
ensure: present
61+
- name: pgrouting
6862
```
6963

7064
### 3. Verify installation
@@ -88,7 +82,7 @@ connect to the container and run:
8882

8983
```bash
9084
cd /extensions/postgis/lib
91-
LD_LIBRARY_PATH=/extensions/postgis/system ldd address_standardizer* postgis*
85+
LD_LIBRARY_PATH=/extensions/postgis/system ldd address_standardizer* postgis* libpgrouting*
9286
```
9387

9488
Make sure there are no missing shared libraries.

postgis/test/chainsaw-test.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: verify-postgis-extensions
5+
spec:
6+
timeouts:
7+
apply: 5s
8+
assert: 3m
9+
delete: 30s
10+
description: Verify all PostGIS related extensions are properly installed
11+
steps:
12+
- name: Create a Cluster with the extension
13+
try:
14+
- apply:
15+
file: cluster.yaml
16+
- apply:
17+
file: database.yaml
18+
- assert:
19+
file: cluster-assert.yaml
20+
- assert:
21+
file: database-assert.yaml
22+
23+
- name: Verify all extensions are installed
24+
try:
25+
- apply:
26+
file: check-extension.yaml
27+
- assert:
28+
file: check-extension-assert.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: extension-installed
5+
status:
6+
succeeded: 1

postgis/test/check-extension.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: extension-installed
5+
spec:
6+
template:
7+
spec:
8+
restartPolicy: OnFailure
9+
containers:
10+
- name: data-test
11+
env:
12+
- name: DB_URI
13+
valueFrom:
14+
secretKeyRef:
15+
name: (join('-', [$values.name, 'app']))
16+
key: uri
17+
image: alpine/psql:latest
18+
command: ['sh', '-c']
19+
args:
20+
- |
21+
set -e
22+
DB_URI=$(echo $DB_URI | sed "s|/\*|/|")
23+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'postgis')" -q)" = "t"
24+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'postgis_raster')" -q)" = "t"
25+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'postgis_sfcgal')" -q)" = "t"
26+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'fuzzystrmatch')" -q)" = "t"
27+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'address_standardizer')" -q)" = "t"
28+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'address_standardizer_data_us')" -q)" = "t"
29+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'postgis_tiger_geocoder')" -q)" = "t"
30+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'postgis_topology')" -q)" = "t"
31+
test "$(psql "$DB_URI" -tAc "SELECT EXISTS (SELECT FROM pg_catalog.pg_extension WHERE extname = 'pgrouting')" -q)" = "t"

postgis/test/cluster-assert.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: ($values.name)
5+
status:
6+
readyInstances: 1
7+
phase: Cluster in healthy state
8+
image: ($values.pg_image)

postgis/test/cluster.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: ($values.name)
5+
spec:
6+
imageName: ($values.pg_image)
7+
instances: 1
8+
9+
storage:
10+
size: 1Gi
11+
12+
postgresql:
13+
shared_preload_libraries: ($values.shared_preload_libraries)
14+
extensions:
15+
- name: ($values.name)
16+
image:
17+
reference: ($values.extension_image)
18+
extension_control_path: ($values.extension_control_path)
19+
dynamic_library_path: ($values.dynamic_library_path)
20+
ld_library_path: ($values.ld_library_path)

postgis/test/database-assert.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Database
3+
metadata:
4+
name: (join('-', [$values.name, 'app']))
5+
status:
6+
applied: true
7+
extensions:
8+
- applied: true
9+
name: ($values.sql_name)
10+
- applied: true
11+
name: postgis_raster
12+
- applied: true
13+
name: postgis_sfcgal
14+
- applied: true
15+
name: fuzzystrmatch
16+
- applied: true
17+
name: address_standardizer
18+
- applied: true
19+
name: address_standardizer_data_us
20+
- applied: true
21+
name: postgis_tiger_geocoder
22+
- applied: true
23+
name: postgis_topology
24+
- applied: true
25+
name: pgrouting
26+
observedGeneration: 1

postgis/test/database.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: postgresql.cnpg.io/v1
2+
kind: Database
3+
metadata:
4+
name: (join('-', [$values.name, 'app']))
5+
spec:
6+
name: app
7+
owner: app
8+
cluster:
9+
name: ($values.name)
10+
extensions:
11+
- name: ($values.sql_name)
12+
- name: postgis_raster
13+
- name: postgis_sfcgal
14+
- name: fuzzystrmatch
15+
- name: address_standardizer
16+
- name: address_standardizer_data_us
17+
- name: postgis_tiger_geocoder
18+
- name: postgis_topology
19+
- name: pgrouting

0 commit comments

Comments
 (0)