diff --git a/tests/expected/auto/mb_jpg.json b/tests/expected/auto/mb_jpg.json index ff08e27b5..0ea277215 100644 --- a/tests/expected/auto/mb_jpg.json +++ b/tests/expected/auto/mb_jpg.json @@ -4,9 +4,9 @@ "http://localhost:3111/geography-class-jpg/{z}/{x}/{y}" ], "bounds": [ - -180.0, + -180, -85.0511, - 180.0, + 180, 85.0511 ], "description": "One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ", diff --git a/tests/expected/auto/mb_png.json b/tests/expected/auto/mb_png.json index 11ec3b88f..55c42294b 100644 --- a/tests/expected/auto/mb_png.json +++ b/tests/expected/auto/mb_png.json @@ -4,14 +4,14 @@ "http://localhost:3111/geography-class-png/{z}/{x}/{y}" ], "bounds": [ - -180.0, + -180, -85.0511, - 180.0, + 180, 85.0511 ], "center": [ - 0.0, - 20.0, + 0, + 20, 0 ], "description": "One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ", diff --git a/tests/expected/auto/pmt.json b/tests/expected/auto/pmt.json index 9d9f6370f..96f570c07 100644 --- a/tests/expected/auto/pmt.json +++ b/tests/expected/auto/pmt.json @@ -4,14 +4,14 @@ "http://localhost:3111/stamen_toner__raster_CC-BY-ODbL_z3/{z}/{x}/{y}" ], "bounds": [ - -180.0, - -85.0, - 180.0, - 85.0 + -180, + -85, + 180, + 85 ], "center": [ - 0.0, - 0.0, + 0, + 0, 0 ], "maxzoom": 3, diff --git a/tests/expected/auto/table_source.json b/tests/expected/auto/table_source.json index f429acd09..609c974b5 100644 --- a/tests/expected/auto/table_source.json +++ b/tests/expected/auto/table_source.json @@ -12,10 +12,10 @@ } ], "bounds": [ - -2.0, - -1.0, + -2, + -1, 142.84131509869133, - 45.0 + 45 ], "name": "table_source", "foo": { diff --git a/tests/test.sh b/tests/test.sh index 1675918fd..8e73fdf6e 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -34,7 +34,7 @@ function wait_for { PROC_NAME=$2 TEST_URL=$3 echo "Waiting for $PROC_NAME ($PROCESS_ID) to start by checking $TEST_URL to be valid..." - for i in {1..60}; do + for _ in {1..60}; do if $CURL "$TEST_URL" 2>/dev/null >/dev/null; then echo "$PROC_NAME is up!" if [[ "$PROC_NAME" == "Martin" ]]; then @@ -42,7 +42,7 @@ function wait_for { fi return fi - if ps -p $PROCESS_ID > /dev/null ; then + if ps -p "$PROCESS_ID" > /dev/null ; then echo "$PROC_NAME is not up yet, waiting for $TEST_URL ..." sleep 1 else @@ -62,9 +62,9 @@ function kill_process { PROCESS_ID=$1 PROC_NAME=$2 echo "Waiting for $PROC_NAME ($PROCESS_ID) to stop..." - kill $PROCESS_ID - for i in {1..50}; do - if ps -p $PROCESS_ID > /dev/null ; then + kill "$PROCESS_ID" + for _ in {1..50}; do + if ps -p "$PROCESS_ID" > /dev/null ; then sleep 0.1 else echo "$PROC_NAME ($PROCESS_ID) has stopped" @@ -72,22 +72,21 @@ function kill_process { fi done echo "$PROC_NAME did not stop in time, killing it" - kill -9 $PROCESS_ID + kill -9 "$PROCESS_ID" # wait for it to die using timeout and wait - timeout -k 1s 1s wait $PROCESS_ID || true; + timeout -k 1s 1s wait "$PROCESS_ID" || true; } -test_jsn() -{ +test_jsn() { FILENAME="$TEST_OUT_DIR/$1.json" URL="$MARTIN_URL/$2" echo "Testing $(basename "$FILENAME") from $URL" - $CURL "$URL" | jq -e > "$FILENAME" + # jq before 1.6 had a different float->int behavior, so trying to make it consistent in all + $CURL "$URL" | jq -e 'walk(if type == "number" then .+0.0 else . end)' > "$FILENAME" } -test_pbf() -{ +test_pbf() { FILENAME="$TEST_OUT_DIR/$1.pbf" URL="$MARTIN_URL/$2" @@ -100,8 +99,7 @@ test_pbf() fi } -test_png() -{ +test_png() { # 3rd argument is optional, .png by default FILENAME="$TEST_OUT_DIR/$1.${3:-png}" URL="$MARTIN_URL/$2" @@ -114,15 +112,12 @@ test_png() fi } -test_jpg() -{ +test_jpg() { # test_png can test any image format, but this is a separate function to make it easier to find all the jpeg tests - test_png $1 $2 jpg + test_png "$1" "$2" jpg } - -test_font() -{ +test_font() { FILENAME="$TEST_OUT_DIR/$1.pbf" URL="$MARTIN_URL/$2" @@ -131,8 +126,7 @@ test_font() } # Delete a line from a file $1 that matches parameter $2 -remove_line() -{ +remove_line() { FILE="$1" LINE_TO_REMOVE="$2" >&2 echo "Removing line '$LINE_TO_REMOVE' from $FILE" @@ -140,8 +134,7 @@ remove_line() mv "${FILE}.tmp" "${FILE}" } -test_log_has_str() -{ +test_log_has_str() { LOG_FILE="$1" EXPECTED_TEXT="$2" echo "Checking $LOG_FILE for expected text: '$EXPECTED_TEXT'" @@ -149,8 +142,7 @@ test_log_has_str() remove_line "$LOG_FILE" "$EXPECTED_TEXT" } -test_martin_cp() -{ +test_martin_cp() { TEST_NAME="$1" ARG=("${@:2}") @@ -171,11 +163,9 @@ test_martin_cp() # These tend to vary between runs. In theory, vacuuming might make it the same. remove_line "$SUMMARY_FILE" "File size: " remove_line "$SUMMARY_FILE" "Page count: " - } -validate_log() -{ +validate_log() { LOG_FILE="$1" >&2 echo "Validating log file $LOG_FILE" @@ -190,7 +180,10 @@ validate_log() fi } +echo "------------------------------------------------------------------------------------------------------------------------" curl --version +jq --version +grep --version # Make sure all targets are built - this way it won't timeout while waiting for it to start # If set to "-", skip this step (e.g. when testing a pre-built binary) @@ -199,7 +192,6 @@ if [[ "$MARTIN_BUILD_ALL" != "-" ]]; then $MARTIN_BUILD_ALL fi - echo "------------------------------------------------------------------------------------------------------------------------" echo "Check HTTP server is running" $CURL --head "$STATICS_URL/webp2.pmtiles" @@ -217,10 +209,10 @@ export DATABASE_URL="$MARTIN_DATABASE_URL" set -x $MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" & -MARTIN_PROC_ID=`jobs -p | tail -n 1` +MARTIN_PROC_ID=$(jobs -p | tail -n 1) { set +x; } 2> /dev/null trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM -wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health" +wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health" unset DATABASE_URL >&2 echo "Test catalog" @@ -295,7 +287,7 @@ test_pbf points_empty_srid_0_0_0 points_empty_srid/0/0/0 test_jsn tbl_comment MixPoints test_jsn fnc_comment function_Mixed_Name -kill_process $MARTIN_PROC_ID Martin +kill_process "$MARTIN_PROC_ID" Martin test_log_has_str "$LOG_FILE" 'WARN martin::pg::query_tables] Table public.table_source has no spatial index on column geom' test_log_has_str "$LOG_FILE" 'WARN martin::fonts] Ignoring duplicate font Overpass Mono Regular from tests' @@ -314,16 +306,16 @@ mkdir -p "$TEST_OUT_DIR" ARG=(--save-config "${TEST_OUT_DIR}/save_config.yaml" tests/fixtures/pmtiles2) set -x $MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" & -MARTIN_PROC_ID=`jobs -p | tail -n 1` +MARTIN_PROC_ID=$(jobs -p | tail -n 1) { set +x; } 2> /dev/null trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM -wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health" +wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health" >&2 echo "Test catalog" test_jsn catalog_auto catalog -kill_process $MARTIN_PROC_ID Martin +kill_process "$MARTIN_PROC_ID" Martin validate_log "$LOG_FILE" @@ -339,10 +331,10 @@ ARG=(--config tests/config.yaml --max-feature-count 1000 --save-config "${TEST_O export DATABASE_URL="$MARTIN_DATABASE_URL" set -x $MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" & -MARTIN_PROC_ID=`jobs -p | tail -n 1` +MARTIN_PROC_ID=$(jobs -p | tail -n 1) { set +x; } 2> /dev/null trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM -wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health" +wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health" unset DATABASE_URL >&2 echo "Test catalog" @@ -379,7 +371,7 @@ test_font font_3 font/Overpass%20Mono%20Regular,Overpass%20Mono%20Light/0-2 test_jsn tbl_comment_cfg MixPoints test_jsn fnc_comment_cfg fnc_Mixed_Name -kill_process $MARTIN_PROC_ID Martin +kill_process "$MARTIN_PROC_ID" Martin test_log_has_str "$LOG_FILE" 'WARN martin::pg::query_tables] Table public.table_source has no spatial index on column geom' test_log_has_str "$LOG_FILE" 'WARN martin::fonts] Ignoring duplicate font Overpass Mono Regular from tests' validate_log "$LOG_FILE" @@ -435,18 +427,14 @@ if [[ "$MBTILES_BIN" != "-" ]]; then $MBTILES_BIN meta-get ./tests/fixtures/mbtiles/world_cities.mbtiles missing_value 2>&1 | tee "$TEST_OUT_DIR/meta-get_missing_value.txt" $MBTILES_BIN validate ./tests/fixtures/mbtiles/zoomed_world_cities.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-ok.txt" - set +e - $MBTILES_BIN validate ./tests/fixtures/files/invalid-tile-idx.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-tiles.txt" - if [[ $? -eq 0 ]]; then + if $MBTILES_BIN validate ./tests/fixtures/files/invalid-tile-idx.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-tiles.txt"; then echo "ERROR: validate with invalid-tile-idx.mbtiles should have failed" exit 1 fi - $MBTILES_BIN validate ./tests/fixtures/files/bad_hash.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-hash.txt" - if [[ $? -eq 0 ]]; then + if $MBTILES_BIN validate ./tests/fixtures/files/bad_hash.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-hash.txt"; then echo "ERROR: validate with bad_hash.mbtiles should have failed" exit 1 fi - set -e cp ./tests/fixtures/files/bad_hash.mbtiles "$TEST_TEMP_DIR/fix_bad_hash.mbtiles" $MBTILES_BIN validate --agg-hash update "$TEST_TEMP_DIR/fix_bad_hash.mbtiles" 2>&1 | tee "$TEST_OUT_DIR/validate-fix.txt"