Skip to content
Snippets Groups Projects
Verified Commit 57cbb7f7 authored by David Hoese's avatar David Hoese
Browse files

Add single geotiff creation to unit test and verify content

parent 6290a127
No related branches found
No related tags found
No related merge requests found
Pipeline #36982 failed with stages
in 1 minute and 54 seconds
......@@ -30,8 +30,9 @@ C01_ISOTIME="2022-03-02T19:40:32"
base_tmp_dir="__TOBECREATED__"
setup_test() {
base_tmp_dir=$(mktemp -d --suffix="-geotiffs")
base_tmp_dir=$(mktemp -d ${TMPDIR:-/tmp}/mapserver-tests-XXXXXXX)
cd "${base_tmp_dir}"
chmod 777 .
echo "Temporary directory: ${base_tmp_dir}"
docker network create ${NETWORK_NAME}
......@@ -54,21 +55,23 @@ graceful_exit() {
add_shapefile_content() {
debug "Creating fake shapefile directory for C01"
docker exec test mkdir -p /data/tiles/g16/abi/radf/C01
gtiff_location=$1
docker exec test bash -c "mkdir -p /data/tiles/g16/abi/radf/C01; chmod -R a+rwX /data/tiles"
debug "Creating fake shapefile file for C01"
docker exec -i test python3 <<EOF
import fiona
from shapely.geometry import mapping, box
from glob import glob
s_file = fiona.open('/data/tiles/g16/abi/radf/C01/C01.shp',
'w',
driver='ESRI Shapefile',
schema={'geometry': 'Polygon', 'properties': {'location': 'str', 'time': 'str:19'}})
bbox = mapping(box(-50000, -50000, 50000, 50000))
bbox = mapping(box(-25000000, -25000000, 25000000, 25000000))
s_file.write({
"geometry": bbox,
"properties": {
"location": "/data/tiles/g16/abi/radf/${C01_GTIFF_NAME}",
"location": "${gtiff_location}",
"time": "${C01_ISOTIME}",
},
})
......@@ -98,13 +101,14 @@ EOF
add_postgres_content() {
debug "Creating values for fake DB row for C01"
gtiff_location=$1
insert_values=$(docker exec -i test python3 <<EOF
from shapely.geometry import box
from shapely import wkb
dt_str = "${C01_ISOTIME}"
location = "/data/tiles/g16/abi/radf/${C01_GTIFF_NAME}"
bbox = box(-50000, -50000, 50000, 50000)
location = "${gtiff_location}"
bbox = box(-25000000, -25000000, 25000000, 25000000)
bbox_wkb = wkb.dumps(bbox, hex=True, srid=930916)
values = (dt_str, location, bbox_wkb)
print(repr(values))
......@@ -118,9 +122,29 @@ INSERT into g16_abi_radf_l1b_c01 (start_time, location, bbox_geometry)
EOF
}
create_fake_geotiff() {
bucket_name="g16_abi_radf_l1b_C01"
mkdir -p "${bucket_name}"
gtiff_fn="${bucket_name}/${C01_GTIFF_NAME}"
docker exec -i test python3 <<EOF
import rasterio
from rasterio.transform import Affine
import numpy as np
transform = Affine.translation(-2500 * 1000 - 500, 2500 * 1000 - 500) * Affine.scale(1000, 1000)
with rasterio.open("/data/${gtiff_fn}", "w", driver='GTiff', height=5000, width=5000, dtype=np.uint8, count=1,
crs="+proj=geos +sweep=x +lon_0=-75.0 +h=35786023 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs", transform=transform) as gtiff_file:
data = np.repeat(np.linspace(0, 255, 5000, dtype=np.uint8)[None, :], 5000, axis=0)
gtiff_file.write(data, 1)
EOF
creation_status=$?
echo ${gtiff_fn}
return $creation_status
}
start_test_container() {
debug "Starting test docker container (${image_url}:${image_tag})..."
docker run --rm -d --network ${NETWORK_NAME} --name test -p 8888:80 $@ ${image_url}:${image_tag}
docker run --rm -d --network ${NETWORK_NAME} --name test -p 8888:80 -v "$(pwd)":"/data" $@ ${image_url}:${image_tag}
start_status=$?
# just wait a bit to let the server start
sleep 2
......@@ -188,15 +212,31 @@ curl_layer_times() {
}
curl_empty_tile() {
debug "Starting curl basic mapfile request..."
debug "Starting curl basic mapfile request for non-existent tile..."
# NOTE: The time doesn't actually exist and no image data is available. A blank image should be returned
curl --fail -sS -o "empty_tile.png" "http://localhost:8888/wms/g16/abi/radf/l1b?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=-1330667.479176%2c-2773559.926648%2c2773559.926648%2c1330667.479176&WIDTH=256&HEIGHT=256&FORMAT=rgba&SRS=EPSG%3a930916&LAYERS=C01&TIME=2022-04-20T16:00:21Z" >/dev/null || pg_exit_status=1
check_image_content "empty_tile.png" 0
curl --fail -sS -o "empty_tile.png" "http://localhost:8888/wms/g16/abi/radf/l1b?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=-2500000%2c-2500000%2c2500000%2c2500000&WIDTH=256&HEIGHT=256&FORMAT=rgba&SRS=EPSG%3a930916&LAYERS=C01&TIME=2022-04-20T16:00:12Z" >/dev/null
cp empty_tile.png /tmp/empty_tile_test.png
check_image_content "empty_tile.png" 1
}
curl_valid_tile() {
debug "Starting curl basic mapfile request for valid tile..."
curl --fail -sS -o "valid_tile.png" "http://localhost:8888/wms/g16/abi/radf/l1b?VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&STYLES=&BBOX=-2500000%2c-2500000%2c2500000%2c2500000&WIDTH=256&HEIGHT=256&FORMAT=rgba&SRS=EPSG%3a930916&LAYERS=C01&TIME=${C01_ISOTIME}Z" >/dev/null
cp valid_tile.png /tmp/valid_tile.png
check_image_content "valid_tile.png" 0
}
check_image_content() {
img_filename=$1
pixel_value=$2
all_zero=$2
# if it is an XML file then it wasn't a successful download
grep_found_xml=1
grep "<?xml" $img_filename || grep_found_xml=0
if [[ $grep_found_xml -ne 0 ]]; then
error "Image being checked is XML file"
cat $img_filename
return 1
fi
docker exec -i test pip install pillow >/dev/null
incontainer_file="/tmp/$(basename $img_filename)"
docker cp $img_filename test:${incontainer_file}
......@@ -211,7 +251,12 @@ from PIL import Image
img = Image.open("${incontainer_file}")
img_arr = np.asarray(img)
assert img_arr.shape == (256, 256, 4)
assert (img_arr[:, :, :3] == ${pixel_value}).all()
if ${all_zero} == 1:
print("\tChecking RGB data is all 0s")
assert (img_arr[:, :, :3] == 0).all()
else:
print("\tChecking RGB data is not all 0s")
assert (img_arr[:, :, :3] != 0).any()
EOF
}
......@@ -220,11 +265,13 @@ run_basic_shapefile_tests() {
setup_test
debug "Starting shapefile tests..."
start_test_container
add_shapefile_content
gtiff_fn="/data/$(create_fake_geotiff)"
add_shapefile_content "${gtiff_fn}"
curl_index
curl_layer_times "[\"${C01_ISOTIME}\"]"
curl_empty_tile
curl_valid_tile
teardown_test
debug "SUCCESS: Shapefile test completed successfully"
}
......@@ -234,16 +281,16 @@ run_basic_postgres_tests() {
debug "Starting postgres tests..."
start_postgres
start_pg_test_container
add_shapefile_content
gtiff_fn="/data/$(create_fake_geotiff)"
add_shapefile_content "${gtiff_fn}"
add_postgres_projections
add_postgres_tables
add_postgres_content
# TODO: Verify empty tile is empty
# TODO: Add fake geotiff and tile check for inserted time and verify non-empty result
add_postgres_content "${gtiff_fn}"
curl_index
curl_layer_times "[\"${C01_ISOTIME}\"]"
curl_empty_tile
curl_valid_tile
debug "SUCCESS: Postgres test completed successfully"
teardown_test
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment