From 9d50970e729bd48c466eade82cd651dd8b6f2e76 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 5 Oct 2023 02:25:24 -0400 Subject: [PATCH] wip --- martin-mbtiles/tests/mbtiles.rs | 48 ++++------ ...> mbtiles__convert@v1__z6__flat-flat.snap} | 0 ...> mbtiles__convert@v1__z6__flat-hash.snap} | 0 ...> mbtiles__convert@v1__z6__flat-norm.snap} | 0 ...> mbtiles__convert@v1__z6__hash-flat.snap} | 0 ...> mbtiles__convert@v1__z6__hash-hash.snap} | 0 ...> mbtiles__convert@v1__z6__hash-norm.snap} | 0 ...> mbtiles__convert@v1__z6__norm-flat.snap} | 0 ...> mbtiles__convert@v1__z6__norm-hash.snap} | 0 ...> mbtiles__convert@v1__z6__norm-norm.snap} | 0 ...databases@v1-no-hash__flat-with-hash.snap} | 0 ... mbtiles__databases@v1-no-hash__flat.snap} | 0 ...es__databases@v1-no-hash__normalized.snap} | 0 ...btiles__databases@v1__flat-with-hash.snap} | 0 ....snap => mbtiles__databases@v1__flat.snap} | 0 ...=> mbtiles__databases@v1__normalized.snap} | 0 ...mbtiles__databases@v2__flat-with-hash.snap | 53 +++++++++++ .../mbtiles__databases@v2__flat.snap | 45 ++++++++++ .../mbtiles__databases@v2__normalized.snap | 90 +++++++++++++++++++ 19 files changed, 204 insertions(+), 32 deletions(-) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__flat-flat.snap => mbtiles__convert@v1__z6__flat-flat.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__flat-hash.snap => mbtiles__convert@v1__z6__flat-hash.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__flat-norm.snap => mbtiles__convert@v1__z6__flat-norm.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__hash-flat.snap => mbtiles__convert@v1__z6__hash-flat.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__hash-hash.snap => mbtiles__convert@v1__z6__hash-hash.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__hash-norm.snap => mbtiles__convert@v1__z6__hash-norm.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__norm-flat.snap => mbtiles__convert@v1__z6__norm-flat.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__norm-hash.snap => mbtiles__convert@v1__z6__norm-hash.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__convert@v1_z2__norm-norm.snap => mbtiles__convert@v1__z6__norm-norm.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_orig__hash.snap => mbtiles__databases@v1-no-hash__flat-with-hash.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_orig__flat.snap => mbtiles__databases@v1-no-hash__flat.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_orig__norm.snap => mbtiles__databases@v1-no-hash__normalized.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_cp__hash.snap => mbtiles__databases@v1__flat-with-hash.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_cp__flat.snap => mbtiles__databases@v1__flat.snap} (100%) rename martin-mbtiles/tests/snapshots/{mbtiles__copy@v1_cp__norm.snap => mbtiles__databases@v1__normalized.snap} (100%) create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat-with-hash.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat.snap create mode 100644 martin-mbtiles/tests/snapshots/mbtiles__databases@v2__normalized.snap diff --git a/martin-mbtiles/tests/mbtiles.rs b/martin-mbtiles/tests/mbtiles.rs index 88cf91977..595db9d98 100644 --- a/martin-mbtiles/tests/mbtiles.rs +++ b/martin-mbtiles/tests/mbtiles.rs @@ -5,11 +5,10 @@ use std::str::from_utf8; use ctor::ctor; use martin_mbtiles::MbtType::{Flat, FlatWithHash, Normalized}; use martin_mbtiles::{apply_diff, create_flat_tables, MbtResult, MbtType, Mbtiles, MbtilesCopier}; +use pretty_assertions::assert_eq as pretty_assert_eq; use rstest::{fixture, rstest}; use serde::Serialize; use sqlx::{query, query_as, Executor as _, Row, SqliteConnection}; - -use pretty_assertions::assert_eq as pretty_assert_eq; const TILES_V1: &str = " INSERT INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES (5, 0, 0, cast('same' as blob)) @@ -139,42 +138,26 @@ type Databases = HashMap<(&'static str, MbtType), Vec>; #[once] fn databases() -> Databases { futures::executor::block_on(async { + let mem = Mbtiles::new(":memory:").unwrap(); let mut result = HashMap::new(); for &typ in &[Flat, FlatWithHash, Normalized] { - let (_, mut cn) = + let (mbt, mut cn) = new_file_no_hash!(databases, typ, METADATA_V1, TILES_V1, "v1-no-hash-{typ}"); - result.insert(("v1_no_hash", typ), dump(&mut cn).await.unwrap()); + let dmp = assert_dump!(&mut cn, "v1-no-hash__{typ}"); + result.insert(("v1_no_hash", typ), dmp); - let (_, mut cn) = new_file!(databases, typ, METADATA_V1, TILES_V1, "v1-{typ}"); - result.insert(("v1", typ), dump(&mut cn).await.unwrap()); + let mut cn = copier(&mbt, &mem).run().await.unwrap(); + let dmp = assert_dump!(&mut cn, "v1__{typ}"); + result.insert(("v1", typ), dmp); let (_, mut cn) = new_file!(databases, typ, METADATA_V2, TILES_V2, "v2-{typ}"); - result.insert(("v2", typ), dump(&mut cn).await.unwrap()); + let dmp = assert_dump!(&mut cn, "v2__{typ}"); + result.insert(("v2", typ), dmp); } result }) } -#[rstest] -#[actix_rt::test] -async fn copy( - #[values(Flat, FlatWithHash, Normalized)] frm_type: MbtType, - databases: &Databases, -) -> MbtResult<()> { - let frm = shorten(frm_type); - let mem = Mbtiles::new(":memory:")?; - let (frm_mbt, mut frm_cn) = new_file_no_hash!(copy, frm_type, METADATA_V1, TILES_V1, "{frm}"); - - let dmp = assert_dump!(&mut frm_cn, "v1_orig__{frm}"); - pretty_assert_eq!(databases.get(&("v1_no_hash", frm_type)).unwrap(), &dmp); - - let opt = copier(&frm_mbt, &mem); - let dmp = assert_dump!(&mut opt.run().await?, "v1_cp__{frm}"); - pretty_assert_eq!(databases.get(&("v1", frm_type)).unwrap(), &dmp); - - Ok(()) -} - #[rstest] #[trace] #[actix_rt::test] @@ -196,7 +179,7 @@ async fn convert( opt.dst_type = Some(dst_type); opt.zoom_levels.insert(6); let z6only = dump(&mut opt.run().await?).await?; - assert_snapshot!(z6only, "v1_z2__{frm}-{to}"); + assert_snapshot!(z6only, "v1__z6__{frm}-{to}"); let mut opt = copier(&frm_mbt, &mem); opt.dst_type = Some(dst_type); @@ -245,7 +228,7 @@ async fn diff_apply( let (tar1_mbt, mut tar1_cn) = new_file! {diff_apply, *target_type, METADATA_V1, TILES_V1, "apply__{src}@{dif}={dst}__to__{tar}-v1"}; apply_diff(path(&tar1_mbt), path(&dst_mbt)).await?; let dmp = dump(&mut tar1_cn).await?; - // pretty_assert_eq!(databases.get(&("v2", *target_type)).unwrap(), &dmp); + // pretty_assert_eq!(&dmp, expected_v2); if &dmp != expected_v2 { assert_snapshot!(dmp, "v2_applied__{src}@{dif}={dst}__to__{tar}__bad_from_v1"); } @@ -253,9 +236,10 @@ async fn diff_apply( let (tar2_mbt, mut tar2_cn) = new_file! {diff_apply, *target_type, METADATA_V2, TILES_V2, "apply__{src}@{dif}={dst}__to__{tar}-v2"}; apply_diff(path(&tar2_mbt), path(&dst_mbt)).await?; let dmp = dump(&mut tar2_cn).await?; - if &dmp != expected_v2 { - assert_snapshot!(dmp, "v2_applied__{src}@{dif}={dst}__to__{tar}__bad_from_v2"); - } + pretty_assert_eq!(&dmp, expected_v2); + // if &dmp != expected_v2 { + // assert_snapshot!(dmp, "v2_applied__{src}@{dif}={dst}__to__{tar}__bad_from_v2"); + // } } Ok(()) diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-flat.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-flat.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-flat.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-hash.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-hash.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-hash.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-norm.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__flat-norm.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__flat-norm.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-flat.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-flat.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-flat.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-hash.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-hash.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-hash.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-norm.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__hash-norm.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__hash-norm.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-flat.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-flat.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-flat.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-hash.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-hash.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-hash.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-norm.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__convert@v1_z2__norm-norm.snap rename to martin-mbtiles/tests/snapshots/mbtiles__convert@v1__z6__norm-norm.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__flat-with-hash.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__hash.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__flat-with-hash.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__flat.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__flat.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__flat.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__normalized.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_orig__norm.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1-no-hash__normalized.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1__flat-with-hash.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__hash.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1__flat-with-hash.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1__flat.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__flat.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1__flat.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__norm.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v1__normalized.snap similarity index 100% rename from martin-mbtiles/tests/snapshots/mbtiles__copy@v1_cp__norm.snap rename to martin-mbtiles/tests/snapshots/mbtiles__databases@v1__normalized.snap diff --git a/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat-with-hash.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat-with-hash.snap new file mode 100644 index 000000000..bed8f5a68 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat-with-hash.snap @@ -0,0 +1,53 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: actual_value +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "5364C57282B73C341D5D801B8F7675C4" )', + '( "md-edit", "value - v2" )', + '( "md-new", "value - new" )', + '( "md-same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE TABLE tiles_with_hash ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + tile_hash text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 5, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 5, 0, 1, blob(edit-v2), "FF76830FF90D79BB335884F256031731" )', + '( 5, 1, 0, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 6, 0, 0, blob(same), "51037A4A37730F52C8732586D3AAA316" )', + '( 6, 0, 1, blob(edit-v2a), "03132BFACDB00CC63D6B7DD98D974DD5" )', + '( 6, 1, 4, blob(one-keep-one-remove), "EFC416C7C53A81E7363BE6C1A389131A" )', + '( 6, 1, 6, blob(new), "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles_with_hash' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT zoom_level, tile_column, tile_row, tile_data FROM tiles_with_hash''' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat.snap new file mode 100644 index 000000000..fd048bec9 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__flat.snap @@ -0,0 +1,45 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: actual_value +--- +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "5364C57282B73C341D5D801B8F7675C4" )', + '( "md-edit", "value - v2" )', + '( "md-new", "value - new" )', + '( "md-same", "value - same" )', +] + +[[]] +type = 'table' +tbl_name = 'tiles' +sql = ''' +CREATE TABLE tiles ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_data blob, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 5, 0, 0, blob(same) )', + '( 5, 0, 1, blob(edit-v2) )', + '( 5, 1, 0, blob(new) )', + '( 6, 0, 0, blob(same) )', + '( 6, 0, 1, blob(edit-v2a) )', + '( 6, 1, 4, blob(one-keep-one-remove) )', + '( 6, 1, 6, blob(new) )', +] + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'index' +tbl_name = 'tiles' diff --git a/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__normalized.snap b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__normalized.snap new file mode 100644 index 000000000..36c59f923 --- /dev/null +++ b/martin-mbtiles/tests/snapshots/mbtiles__databases@v2__normalized.snap @@ -0,0 +1,90 @@ +--- +source: martin-mbtiles/tests/mbtiles.rs +expression: actual_value +--- +[[]] +type = 'table' +tbl_name = 'images' +sql = ''' +CREATE TABLE images ( + tile_id text NOT NULL PRIMARY KEY, + tile_data blob)''' +values = [ + '( "03132BFACDB00CC63D6B7DD98D974DD5", blob(edit-v2a) )', + '( "22AF645D1859CB5CA6DA0C484F1F37EA", blob(new) )', + '( "51037A4A37730F52C8732586D3AAA316", blob(same) )', + '( "EFC416C7C53A81E7363BE6C1A389131A", blob(one-keep-one-remove) )', + '( "FF76830FF90D79BB335884F256031731", blob(edit-v2) )', +] + +[[]] +type = 'table' +tbl_name = 'map' +sql = ''' +CREATE TABLE map ( + zoom_level integer NOT NULL, + tile_column integer NOT NULL, + tile_row integer NOT NULL, + tile_id text, + PRIMARY KEY(zoom_level, tile_column, tile_row))''' +values = [ + '( 5, 0, 0, "51037A4A37730F52C8732586D3AAA316" )', + '( 5, 0, 1, "FF76830FF90D79BB335884F256031731" )', + '( 5, 1, 0, "22AF645D1859CB5CA6DA0C484F1F37EA" )', + '( 6, 0, 0, "51037A4A37730F52C8732586D3AAA316" )', + '( 6, 0, 1, "03132BFACDB00CC63D6B7DD98D974DD5" )', + '( 6, 1, 4, "EFC416C7C53A81E7363BE6C1A389131A" )', + '( 6, 1, 6, "22AF645D1859CB5CA6DA0C484F1F37EA" )', +] + +[[]] +type = 'table' +tbl_name = 'metadata' +sql = ''' +CREATE TABLE metadata ( + name text NOT NULL PRIMARY KEY, + value text)''' +values = [ + '( "agg_tiles_hash", "5364C57282B73C341D5D801B8F7675C4" )', + '( "md-edit", "value - v2" )', + '( "md-new", "value - new" )', + '( "md-same", "value - same" )', +] + +[[]] +type = 'index' +tbl_name = 'images' + +[[]] +type = 'index' +tbl_name = 'map' + +[[]] +type = 'index' +tbl_name = 'metadata' + +[[]] +type = 'view' +tbl_name = 'tiles' +sql = ''' +CREATE VIEW tiles AS + SELECT map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data + FROM map + JOIN images ON images.tile_id = map.tile_id''' + +[[]] +type = 'view' +tbl_name = 'tiles_with_hash' +sql = ''' +CREATE VIEW tiles_with_hash AS + SELECT + map.zoom_level AS zoom_level, + map.tile_column AS tile_column, + map.tile_row AS tile_row, + images.tile_data AS tile_data, + images.tile_id AS tile_hash + FROM map + JOIN images ON images.tile_id = map.tile_id'''