2023-01-01 08:03:21 +03:00
|
|
|
pub use martin::args::Env;
|
|
|
|
use martin::pg::{PgConfig, Pool, TableInfo};
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
use martin::OneOrMany::One;
|
|
|
|
use martin::{Config, IdResolver, OneOrMany, Source, Sources};
|
2023-01-03 19:09:41 +03:00
|
|
|
|
|
|
|
use crate::FauxEnv;
|
2023-01-01 08:03:21 +03:00
|
|
|
|
|
|
|
//
|
2023-01-03 19:09:41 +03:00
|
|
|
// This file is used by many tests and benchmarks.
|
2023-01-01 08:03:21 +03:00
|
|
|
// Each function should allow dead_code as they might not be used by a specific test file.
|
|
|
|
//
|
|
|
|
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
pub type MockSource = (Sources, Config);
|
2023-01-01 08:03:21 +03:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[must_use]
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
pub fn mock_pgcfg(yaml: &str) -> Config {
|
2023-01-01 08:03:21 +03:00
|
|
|
let Ok(db_url) = std::env::var("DATABASE_URL") else {
|
|
|
|
panic!("DATABASE_URL env var is not set. Unable to do integration tests");
|
|
|
|
};
|
|
|
|
let env = FauxEnv(vec![("DATABASE_URL", db_url.into())].into_iter().collect());
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
let cfg: PgConfig = subst::yaml::from_str(yaml, &env).unwrap();
|
|
|
|
let mut config = Config {
|
|
|
|
postgres: Some(One(cfg)),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
config.finalize().unwrap();
|
|
|
|
config
|
2023-01-01 08:03:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub async fn mock_pool() -> Pool {
|
2023-01-03 19:09:41 +03:00
|
|
|
let cfg = mock_pgcfg("connection_string: $DATABASE_URL");
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
let OneOrMany::One(cfg) = cfg.postgres.unwrap() else { panic!() };
|
2023-01-01 08:03:21 +03:00
|
|
|
let res = Pool::new(&cfg).await;
|
|
|
|
res.expect("Failed to create pool")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
pub async fn mock_sources(mut config: Config) -> MockSource {
|
2023-01-01 08:03:21 +03:00
|
|
|
let res = config.resolve(IdResolver::default()).await;
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
let res = res.unwrap_or_else(|e| panic!("Failed to resolve config {config:?}: {e}"));
|
2023-01-01 08:03:21 +03:00
|
|
|
(res, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[must_use]
|
|
|
|
pub fn table<'a>(mock: &'a MockSource, name: &str) -> &'a TableInfo {
|
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 17:31:58 +03:00
|
|
|
let (_, config) = mock;
|
|
|
|
let vals: Vec<&TableInfo> = config
|
|
|
|
.postgres
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.iter()
|
|
|
|
.flat_map(|v| v.tables.iter().map(|vv| vv.get(name)))
|
|
|
|
.flatten()
|
|
|
|
.collect();
|
|
|
|
assert_eq!(vals.len(), 1);
|
|
|
|
vals[0]
|
2023-01-01 08:03:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[must_use]
|
|
|
|
pub fn source<'a>(mock: &'a MockSource, name: &str) -> &'a dyn Source {
|
|
|
|
let (sources, _) = mock;
|
|
|
|
sources.get(name).unwrap().as_ref()
|
|
|
|
}
|