diff --git a/justfile b/justfile index 755b091c8..08289b1ec 100644 --- a/justfile +++ b/justfile @@ -2,10 +2,10 @@ set shell := ["bash", "-c"] -#export DATABASE_URL="postgres://postgres:postgres@localhost:5411/db" +#export DATABASE_URL_PAT="postgres://postgres:postgres@localhost:5411/db" export PGPORT := "5411" -export DATABASE_URL := "postgres://postgres:postgres@localhost:" + PGPORT + "/db" +export DATABASE_URL_PAT := "postgres://postgres:postgres@localhost:" + PGPORT + "/db" export CARGO_TERM_COLOR := "always" #export RUST_LOG := "debug" @@ -38,11 +38,11 @@ debug-page *ARGS: start # Run PSQL utility against the test database psql *ARGS: - psql {{ ARGS }} {{ DATABASE_URL }} + psql {{ ARGS }} {{ DATABASE_URL_PAT }} # Run pg_dump utility against the test database pg_dump *ARGS: - pg_dump {{ ARGS }} {{ DATABASE_URL }} + pg_dump {{ ARGS }} {{ DATABASE_URL_PAT }} # Perform cargo clean to delete all build files clean: clean-test stop @@ -115,7 +115,7 @@ test-ssl-cert: start-ssl-cert mkdir -p $KEY_DIR docker cp martin-db-ssl-cert-1:/etc/ssl/certs/ssl-cert-snakeoil.pem $KEY_DIR/ssl-cert-snakeoil.pem docker cp martin-db-ssl-cert-1:/etc/ssl/private/ssl-cert-snakeoil.key $KEY_DIR/ssl-cert-snakeoil.key - # export DATABASE_URL="$DATABASE_URL?sslmode=verify-full&sslrootcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslkey=$KEY_DIR/ssl-cert-snakeoil.key" + # export DATABASE_URL_PAT="$DATABASE_URL_PAT?sslmode=verify-full&sslrootcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslkey=$KEY_DIR/ssl-cert-snakeoil.key" export PGSSLROOTCERT="$KEY_DIR/ssl-cert-snakeoil.pem" export PGSSLCERT="$KEY_DIR/ssl-cert-snakeoil.pem" export PGSSLKEY="$KEY_DIR/ssl-cert-snakeoil.key" @@ -238,7 +238,7 @@ coverage FORMAT='html': (cargo-install "grcov") # Build and run martin docker image docker-run *ARGS: - docker run -it --rm --net host -e DATABASE_URL -v $PWD/tests:/tests ghcr.io/maplibre/martin {{ ARGS }} + docker run -it --rm --net host -e DATABASE_URL_PAT -v $PWD/tests:/tests ghcr.io/maplibre/martin {{ ARGS }} # Do any git command, ensuring that the testing environment is set up. Accepts the same arguments as git. [no-exit-message] @@ -247,7 +247,7 @@ git *ARGS: start # Print the connection string for the test database print-conn-str: - @echo {{ DATABASE_URL }} + @echo {{ DATABASE_URL_PAT }} # Run cargo fmt and cargo clippy lint: fmt clippy diff --git a/martin/src/args/pg.rs b/martin/src/args/pg.rs index 48fbb5f1f..64eafa61d 100644 --- a/martin/src/args/pg.rs +++ b/martin/src/args/pg.rs @@ -131,10 +131,10 @@ impl PgArgs { if connections.is_empty() { if let Some(s) = env.get_env_str("DATABASE_URL_PAT") { if is_postgresql_string(&s) { - info!("Using env var DATABASE_URL to connect to PostgreSQL"); + info!("Using env var DATABASE_URL_PAT to connect to PostgreSQL"); connections.push(s); } else { - warn!("Environment var DATABASE_URL is not a valid postgres connection string"); + warn!("Environment var DATABASE_URL_PAT is not a valid postgres connection string"); } } } @@ -224,7 +224,7 @@ mod tests { fn test_extract_conn_strings_from_env() { let mut args = Arguments::new(vec![]); let env = FauxEnv( - vec![("DATABASE_URL", os("postgresql://localhost:5432"))] + vec![("DATABASE_URL_PAT", os("postgresql://localhost:5432"))] .into_iter() .collect(), ); @@ -252,7 +252,7 @@ mod tests { let mut args = Arguments::new(vec![]); let env = FauxEnv( vec![ - ("DATABASE_URL", os("postgres://localhost:5432")), + ("DATABASE_URL_PAT", os("postgres://localhost:5432")), ("DEFAULT_SRID", os("10")), ("DANGER_ACCEPT_INVALID_CERTS", os("1")), ("CA_ROOT_FILE", os("file")), @@ -281,7 +281,7 @@ mod tests { let mut args = Arguments::new(vec![]); let env = FauxEnv( vec![ - ("DATABASE_URL", os("postgres://localhost:5432")), + ("DATABASE_URL_PAT", os("postgres://localhost:5432")), ("DEFAULT_SRID", os("10")), ("PGSSLCERT", os("cert")), ("PGSSLKEY", os("key")), diff --git a/martin/tests/pg_function_source_test.rs b/martin/tests/pg_function_source_test.rs index 3e00ef62d..4df5c2a7e 100644 --- a/martin/tests/pg_function_source_test.rs +++ b/martin/tests/pg_function_source_test.rs @@ -13,7 +13,7 @@ fn init() { #[actix_rt::test] async fn function_source_tilejson() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; let tj = source(&mock, "function_zxy_query").get_tilejson(); assert_yaml_snapshot!(tj, @r###" --- @@ -27,7 +27,7 @@ async fn function_source_tilejson() { #[actix_rt::test] async fn function_source_tile() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; let src = source(&mock, "function_zxy_query"); let tile = src .get_tile(&TileCoord { z: 0, x: 0, y: 0 }, &None) @@ -46,7 +46,7 @@ async fn function_source_tile() { #[actix_rt::test] async fn function_source_schemas() { let cfg = mock_pgcfg(indoc! {" - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT auto_publish: tables: false functions: diff --git a/martin/tests/pg_server_test.rs b/martin/tests/pg_server_test.rs index 4757b783c..13a0719ad 100644 --- a/martin/tests/pg_server_test.rs +++ b/martin/tests/pg_server_test.rs @@ -39,7 +39,7 @@ fn test_get(path: &str) -> Request { async fn pg_get_catalog() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/catalog"); @@ -123,7 +123,7 @@ postgres: async fn pg_get_table_source_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: bad_srid: schema: public @@ -158,7 +158,7 @@ postgres: async fn pg_get_table_source_rewrite() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: table_source: schema: public @@ -200,7 +200,7 @@ postgres: async fn pg_get_table_source_tile_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: points2: schema: public @@ -290,7 +290,7 @@ postgres: async fn pg_get_table_source_multiple_geom_tile_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: points2: schema: public @@ -380,7 +380,7 @@ postgres: async fn pg_get_table_source_tile_minmax_zoom_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: points3857: schema: public @@ -488,7 +488,7 @@ postgres: async fn pg_get_function_tiles() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/function_zoom_xy/6/38/20"); @@ -520,7 +520,7 @@ postgres: async fn pg_get_composite_source_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: table_source_multiple_geom.geom2: schema: public @@ -609,7 +609,7 @@ postgres: async fn pg_get_composite_source_tile_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: points_empty_srid: schema: public @@ -699,7 +699,7 @@ postgres: async fn pg_get_composite_source_tile_minmax_zoom_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT tables: points1: schema: public @@ -765,7 +765,7 @@ postgres: async fn pg_null_functions() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/function_null/0/0/0"); @@ -785,7 +785,7 @@ postgres: async fn pg_get_function_source_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/non_existent"); @@ -829,7 +829,7 @@ postgres: async fn pg_get_function_source_ok_rewrite() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = TestRequest::get() @@ -860,7 +860,7 @@ postgres: async fn pg_get_function_source_tile_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/function_zxy_query/0/0/0"); @@ -872,7 +872,7 @@ postgres: async fn pg_get_function_source_tile_minmax_zoom_ok() { let app = create_app! {" postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT functions: function_source1: schema: public @@ -930,7 +930,7 @@ postgres: async fn pg_get_function_source_query_params_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/function_zxy_query_test/0/0/0"); @@ -946,7 +946,7 @@ postgres: async fn pg_get_health_returns_ok() { let app = create_app! { " postgres: - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT "}; let req = test_get("/health"); @@ -957,7 +957,7 @@ postgres: #[actix_rt::test] async fn pg_tables_feature_id() { let cfg = mock_pgcfg(indoc! {" -connection_string: $DATABASE_URL +connection_string: $DATABASE_URL_PAT tables: id_and_prop: schema: MIXEDCASE diff --git a/martin/tests/pg_table_source_test.rs b/martin/tests/pg_table_source_test.rs index b82e990e3..d27c90a87 100644 --- a/martin/tests/pg_table_source_test.rs +++ b/martin/tests/pg_table_source_test.rs @@ -13,7 +13,7 @@ fn init() { #[actix_rt::test] async fn table_source() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; assert_yaml_snapshot!(mock.0.tiles.get_catalog(), @r###" --- MixPoints: @@ -102,7 +102,7 @@ async fn table_source() { #[actix_rt::test] async fn tables_tilejson() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; let tj = source(&mock, "table_source").get_tilejson(); assert_yaml_snapshot!(tj, @r###" --- @@ -125,7 +125,7 @@ async fn tables_tilejson() { #[actix_rt::test] async fn tables_tile_ok() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; let tile = source(&mock, "table_source") .get_tile(&TileCoord { z: 0, x: 0, y: 0 }, &None) .await @@ -137,7 +137,7 @@ async fn tables_tile_ok() { #[actix_rt::test] async fn tables_srid_ok() { let mock = mock_sources(mock_pgcfg(indoc! {" - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT default_srid: 900913 "})) .await; @@ -157,7 +157,7 @@ async fn tables_srid_ok() { #[actix_rt::test] async fn tables_multiple_geom_ok() { - let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await; + let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL_PAT")).await; let source = table(&mock, "table_source_multiple_geom"); assert_eq!(source.geometry_column, "geom1"); @@ -169,7 +169,7 @@ async fn tables_multiple_geom_ok() { #[actix_rt::test] async fn table_source_schemas() { let cfg = mock_pgcfg(indoc! {" - connection_string: $DATABASE_URL + connection_string: $DATABASE_URL_PAT auto_publish: tables: from_schemas: MixedCase diff --git a/martin/tests/utils/mod.rs b/martin/tests/utils/mod.rs index e61dae3d0..19775b4a7 100644 --- a/martin/tests/utils/mod.rs +++ b/martin/tests/utils/mod.rs @@ -15,10 +15,10 @@ pub use test_utils::*; #[must_use] pub fn mock_cfg(yaml: &str) -> Config { - let env = if let Ok(db_url) = std::env::var("DATABASE_URL") { - FauxEnv(vec![("DATABASE_URL", db_url.into())].into_iter().collect()) + let env = if let Ok(db_url) = std::env::var("DATABASE_URL_PAT") { + FauxEnv(vec![("DATABASE_URL_PAT", db_url.into())].into_iter().collect()) } else { - warn!("DATABASE_URL env var is not set. Might not be able to do integration tests"); + warn!("DATABASE_URL_PAT env var is not set. Might not be able to do integration tests"); FauxEnv::default() }; let mut cfg: Config = subst::yaml::from_str(yaml, &env).unwrap(); diff --git a/mbtiles/.env b/mbtiles/.env index ed53de4bf..224a5a6c4 100644 --- a/mbtiles/.env +++ b/mbtiles/.env @@ -1,2 +1,2 @@ -# DATABASE_URL=sqlite:mbtiles/data/geography-class-jpg.mbtiles +# DATABASE_URL_PAT=sqlite:mbtiles/data/geography-class-jpg.mbtiles SQLX_OFFLINE=true diff --git a/tests/config.yaml b/tests/config.yaml index 295772979..ee68c9986 100644 --- a/tests/config.yaml +++ b/tests/config.yaml @@ -11,7 +11,7 @@ worker_processes: 8 # Database configuration. This can also be a list of PG configs. postgres: # Database connection string - connection_string: '${DATABASE_URL:postgresql://postgres@localhost:5432/db}' + connection_string: '${DATABASE_URL_PAT:postgresql://postgres@localhost:5432/db}' # If a spatial table has SRID 0, then this SRID will be used as a fallback default_srid: 4326 diff --git a/tests/test.sh b/tests/test.sh index 798ea9026..d34ce2639 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -MARTIN_DATABASE_URL="${DATABASE_URL:-postgres://postgres@localhost/db}" -unset DATABASE_URL +MARTIN_DATABASE_URL="${DATABASE_URL_PAT:-postgres://postgres@localhost/db}" +unset DATABASE_URL_PAT # TODO: use --fail-with-body to get the response body on failure CURL=${CURL:-curl --silent --show-error --fail --compressed} @@ -208,7 +208,7 @@ TEST_OUT_DIR="${TEST_OUT_BASE_DIR}/${TEST_NAME}" mkdir -p "$TEST_OUT_DIR" ARG=(--default-srid 900913 --auto-bounds calc --save-config "${TEST_OUT_DIR}/save_config.yaml" tests/fixtures/mbtiles tests/fixtures/pmtiles tests/fixtures/pmtiles2 --sprite tests/fixtures/sprites/src1 --font tests/fixtures/fonts/overpass-mono-regular.ttf --font tests/fixtures/fonts) -export DATABASE_URL="$MARTIN_DATABASE_URL" +export DATABASE_URL_PAT="$MARTIN_DATABASE_URL" set -x $MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" & @@ -216,7 +216,7 @@ 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" -unset DATABASE_URL +unset DATABASE_URL_PAT >&2 echo "Test catalog" test_jsn catalog_auto catalog @@ -331,14 +331,14 @@ TEST_OUT_DIR="${TEST_OUT_BASE_DIR}/${TEST_NAME}" mkdir -p "$TEST_OUT_DIR" ARG=(--config tests/config.yaml --max-feature-count 1000 --save-config "${TEST_OUT_DIR}/save_config.yaml" -W 1) -export DATABASE_URL="$MARTIN_DATABASE_URL" +export DATABASE_URL_PAT="$MARTIN_DATABASE_URL" set -x $MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" & 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" -unset DATABASE_URL +unset DATABASE_URL_PAT >&2 echo "Test catalog" test_jsn catalog_cfg catalog @@ -389,7 +389,7 @@ if [[ "$MARTIN_CP_BIN" != "-" ]]; then TEST_OUT_DIR="${TEST_OUT_BASE_DIR}/${TEST_NAME}" mkdir -p "$TEST_OUT_DIR" - export DATABASE_URL="$MARTIN_DATABASE_URL" + export DATABASE_URL_PAT="$MARTIN_DATABASE_URL" CFG=(--default-srid 900913 --auto-bounds calc tests/fixtures/mbtiles tests/fixtures/pmtiles tests/fixtures/pmtiles2) test_martin_cp "flat" "${CFG[@]}" \ @@ -403,7 +403,7 @@ if [[ "$MARTIN_CP_BIN" != "-" ]]; then --min-zoom 0 --max-zoom 6 "--bbox=-2,-1,142.84,45" \ --set-meta "name=normalized" --set-meta=center=0,0,0 - unset DATABASE_URL + unset DATABASE_URL_PAT else echo "Skipping martin-cp tests"