Skip to content

Commit

Permalink
didn't save
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-amuse committed Dec 7, 2023
1 parent 69b5187 commit 3ed4956
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 52 deletions.
14 changes: 7 additions & 7 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions martin/src/args/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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(),
);
Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -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")),
Expand Down
6 changes: 3 additions & 3 deletions martin/tests/pg_function_source_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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###"
---
Expand All @@ -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)
Expand All @@ -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:
Expand Down
36 changes: 18 additions & 18 deletions martin/tests/pg_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions martin/tests/pg_table_source_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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###"
---
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions martin/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion mbtiles/.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3ed4956

Please sign in to comment.