Files
watermaps/deploy/scripts/tests/route-data-helpers.test.sh
BuTzZ 593dbd5f85
Test and publish container images / test (push) Successful in 2m26s
Test and publish container images / publish (push) Failing after 3s
optimized events
2026-07-28 14:36:47 +02:00

127 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
TEST_DIR="$(mktemp -d)"
trap 'rm -rf "$TEST_DIR"' EXIT
export WATERMAPS_DATA_DIR="$TEST_DIR/data"
export WATERMAPS_RUNTIME_DIR="$TEST_DIR/runtime"
mkdir -p "$WATERMAPS_DATA_DIR/local" "$WATERMAPS_RUNTIME_DIR"
# shellcheck source=../common.sh
source "$ROOT_DIR/deploy/scripts/common.sh"
route_file="$(wm_route_file)"
route_marker="$(wm_route_marker)"
write_valid_route() {
cat >"$route_file" <<'JSON'
{
"version": 1,
"generatorVersion": 2,
"source": "germany+netherlands",
"sources": [
{
"region": "germany",
"file": "germany-latest.osm.pbf",
"checksumMd5": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"sizeBytes": 1
},
{
"region": "netherlands",
"file": "netherlands-latest.osm.pbf",
"checksumMd5": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"sizeBytes": 1
}
],
"ways": [{"id": "1"}]
}
JSON
chmod 0644 "$route_file"
}
write_valid_route
wm_write_route_marker "$route_file" "$route_marker"
wm_route_data_ready
sed -i 's/^size_bytes=.*/size_bytes=1/' "$route_marker"
if wm_route_data_ready; then
printf 'Ungültige Markergröße wurde akzeptiert.\n' >&2
exit 1
fi
wm_write_route_marker "$route_file" "$route_marker"
jq '.sources = [.sources[0]] | .source = "germany"' \
"$route_file" >"$route_file.tmp"
mv "$route_file.tmp" "$route_file"
chmod 0644 "$route_file"
wm_write_route_marker "$route_file" "$route_marker"
if wm_route_data_ready; then
printf 'Deutschland-only-Index wurde akzeptiert.\n' >&2
exit 1
fi
write_valid_route
wm_write_route_marker "$route_file" "$route_marker"
chmod 0600 "$route_file"
if wm_route_data_ready; then
printf 'Für den App-Container unlesbarer Index wurde akzeptiert.\n' >&2
exit 1
fi
mkdir -p "$WATERMAPS_DATA_DIR/geofabrik"
printf '%s germany-latest.osm.pbf\n' \
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' \
>"$WATERMAPS_DATA_DIR/geofabrik/germany-latest.osm.pbf.md5"
printf '%s netherlands-latest.osm.pbf\n' \
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' \
>"$WATERMAPS_DATA_DIR/geofabrik/netherlands-latest.osm.pbf.md5"
cat >"$(wm_marine_marker)" <<'MARKER'
format_version=1
generated_at=2026-07-28T00:00:00Z
source=germany+netherlands
germany_md5=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
netherlands_md5=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
total_osm_features=100
harbour_count=10
lock_count=5
bridge_count=20
MARKER
wm_postgres_query() {
printf '100|10|5|20\n'
}
wm_marine_features_ready
wm_postgres_query() {
printf '100|10|0|20\n'
}
if wm_marine_features_ready; then
printf 'Marine-Feature-Marker wurde trotz fehlender Schleusen akzeptiert.\n' >&2
exit 1
fi
wm_postgres_query() {
printf '99|10|5|20\n'
}
if wm_marine_features_ready; then
printf 'Marine-Feature-Marker wurde trotz abweichendem Datenbankbestand akzeptiert.\n' >&2
exit 1
fi
if grep -Eq 'DATABASE_URL:[[:space:]]*""' \
"$ROOT_DIR/docker-compose.yml" \
"$ROOT_DIR/deploy/compose.production.yml"; then
printf 'Compose trennt die App weiterhin explizit von PostGIS.\n' >&2
exit 1
fi
grep -Fq 'condition: service_healthy' "$ROOT_DIR/deploy/compose.production.yml"
grep -Fq '/ready' "$ROOT_DIR/deploy/compose.production.yml"
grep -Fq 'source: ${WATERMAPS_DATA_DIR:-/srv/watermaps-data}/postgres' \
"$ROOT_DIR/deploy/compose.production.yml"
printf 'Routingdaten-, Marine-Feature- und Compose-Prüfungen: OK\n'