From d6232f14181cd4dac597141027134e33333c5b01 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Wed, 27 Sep 2023 11:19:48 +0400 Subject: [PATCH] refactor(test): reorganize integration tests --- .../compression.rs} | 14 +++++------ .../cursor_error.rs} | 14 +++++------ tests/{test_ip.rs => it/ip.rs} | 6 ++--- tests/{common.rs => it/main.rs} | 24 ++++++++++++------- tests/{test_nested.rs => it/nested.rs} | 6 ++--- tests/{test_query.rs => it/query.rs} | 22 ++++++++--------- tests/{test_time.rs => it/time.rs} | 14 +++++------ tests/{test_uuid.rs => it/uuid.rs} | 6 ++--- tests/{test_wa_37420.rs => it/wa_37420.rs} | 6 ++--- tests/{test_watch.rs => it/watch.rs} | 10 ++++---- 10 files changed, 56 insertions(+), 66 deletions(-) rename tests/{test_compression.rs => it/compression.rs} (79%) rename tests/{test_cursor_error.rs => it/cursor_error.rs} (91%) rename tests/{test_ip.rs => it/ip.rs} (95%) rename tests/{common.rs => it/main.rs} (75%) rename tests/{test_nested.rs => it/nested.rs} (93%) rename tests/{test_query.rs => it/query.rs} (92%) rename tests/{test_time.rs => it/time.rs} (97%) rename tests/{test_uuid.rs => it/uuid.rs} (94%) rename tests/{test_wa_37420.rs => it/wa_37420.rs} (95%) rename tests/{test_watch.rs => it/watch.rs} (95%) diff --git a/tests/test_compression.rs b/tests/it/compression.rs similarity index 79% rename from tests/test_compression.rs rename to tests/it/compression.rs index 206c7f5..e9b248e 100644 --- a/tests/test_compression.rs +++ b/tests/it/compression.rs @@ -2,8 +2,6 @@ use serde::{Deserialize, Serialize}; use clickhouse::{Client, Compression, Row}; -mod common; - async fn check(client: Client) { #[derive(Debug, Row, Serialize, Deserialize)] struct MyRow<'a> { @@ -44,25 +42,25 @@ async fn check(client: Client) { assert_eq!(sum_len, 600_000); } -#[common::named] +#[crate::named] #[tokio::test] async fn none() { - let client = common::prepare_database!().with_compression(Compression::None); + let client = prepare_database!().with_compression(Compression::None); check(client).await; } #[cfg(feature = "lz4")] -#[common::named] +#[crate::named] #[tokio::test] async fn lz4() { - let client = common::prepare_database!().with_compression(Compression::Lz4); + let client = prepare_database!().with_compression(Compression::Lz4); check(client).await; } #[cfg(feature = "lz4")] -#[common::named] +#[crate::named] #[tokio::test] async fn lz4_hc() { - let client = common::prepare_database!().with_compression(Compression::Lz4Hc(4)); + let client = prepare_database!().with_compression(Compression::Lz4Hc(4)); check(client).await; } diff --git a/tests/test_cursor_error.rs b/tests/it/cursor_error.rs similarity index 91% rename from tests/test_cursor_error.rs rename to tests/it/cursor_error.rs index 2f1b85a..a26e5a8 100644 --- a/tests/test_cursor_error.rs +++ b/tests/it/cursor_error.rs @@ -1,18 +1,16 @@ use clickhouse::{Client, Compression}; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn deferred() { - let client = common::prepare_database!(); + let client = prepare_database!(); max_execution_time(client, false).await; } -#[common::named] +#[crate::named] #[tokio::test] async fn wait_end_of_query() { - let client = common::prepare_database!(); + let client = prepare_database!(); max_execution_time(client, true).await; } @@ -48,10 +46,10 @@ async fn max_execution_time(mut client: Client, wait_end_of_query: bool) { } #[cfg(feature = "lz4")] -#[common::named] +#[crate::named] #[tokio::test] async fn deferred_lz4() { - let client = common::prepare_database!().with_compression(Compression::Lz4); + let client = prepare_database!().with_compression(Compression::Lz4); client .query("CREATE TABLE test(no UInt32) ENGINE = MergeTree ORDER BY no") diff --git a/tests/test_ip.rs b/tests/it/ip.rs similarity index 95% rename from tests/test_ip.rs rename to tests/it/ip.rs index 966ca09..21efb84 100644 --- a/tests/test_ip.rs +++ b/tests/it/ip.rs @@ -4,12 +4,10 @@ use serde::{Deserialize, Serialize}; use clickhouse::Row; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn smoke() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)] struct MyRow { diff --git a/tests/common.rs b/tests/it/main.rs similarity index 75% rename from tests/common.rs rename to tests/it/main.rs index 26c1b0a..6a24da0 100644 --- a/tests/common.rs +++ b/tests/it/main.rs @@ -1,20 +1,28 @@ -#![allow(dead_code, unused_imports, unused_macros)] - use clickhouse::{sql, Client}; - -const HOST: &str = "localhost:8123"; +use function_name::named; macro_rules! prepare_database { () => { - common::_priv::prepare_database(file!(), function_name!()).await + crate::_priv::prepare_database(file!(), function_name!()).await }; } -pub(crate) use {function_name::named, prepare_database}; -pub(crate) mod _priv { +mod compression; +mod cursor_error; +mod ip; +mod nested; +mod query; +mod time; +mod uuid; +mod wa_37420; +mod watch; + +const HOST: &str = "localhost:8123"; + +mod _priv { use super::*; - pub async fn prepare_database(file_path: &str, fn_name: &str) -> Client { + pub(crate) async fn prepare_database(file_path: &str, fn_name: &str) -> Client { let name = make_db_name(file_path, fn_name); let client = Client::default().with_url(format!("http://{HOST}")); diff --git a/tests/test_nested.rs b/tests/it/nested.rs similarity index 93% rename from tests/test_nested.rs rename to tests/it/nested.rs index daf75b1..9b2fde7 100644 --- a/tests/test_nested.rs +++ b/tests/it/nested.rs @@ -2,12 +2,10 @@ use serde::{Deserialize, Serialize}; use clickhouse::Row; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn smoke() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)] struct MyRow { diff --git a/tests/test_query.rs b/tests/it/query.rs similarity index 92% rename from tests/test_query.rs rename to tests/it/query.rs index 04d566f..4a8e4a9 100644 --- a/tests/test_query.rs +++ b/tests/it/query.rs @@ -2,12 +2,10 @@ use serde::{Deserialize, Serialize}; use clickhouse::{error::Error, Row}; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn smoke() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, Row, Serialize, Deserialize)] struct MyRow<'a> { @@ -54,10 +52,10 @@ async fn smoke() { } } -#[common::named] +#[crate::named] #[tokio::test] async fn fetch_one_and_optional() { - let client = common::prepare_database!(); + let client = prepare_database!(); client .query("CREATE TABLE test(n String) ENGINE = MergeTree ORDER BY n") @@ -90,10 +88,10 @@ async fn fetch_one_and_optional() { } // See #19. -#[common::named] +#[crate::named] #[tokio::test] async fn long_query() { - let client = common::prepare_database!(); + let client = prepare_database!(); client .query("CREATE TABLE test(n String) ENGINE = MergeTree ORDER BY n") @@ -114,10 +112,10 @@ async fn long_query() { } // See #22. -#[common::named] +#[crate::named] #[tokio::test] async fn big_borrowed_str() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, Row, Serialize, Deserialize)] struct MyRow<'a> { @@ -153,10 +151,10 @@ async fn big_borrowed_str() { } // See #31. -#[common::named] +#[crate::named] #[tokio::test] async fn all_floats() { - let client = common::prepare_database!(); + let client = prepare_database!(); client .query("CREATE TABLE test(no UInt32, f Float64) ENGINE = MergeTree ORDER BY no") diff --git a/tests/test_time.rs b/tests/it/time.rs similarity index 97% rename from tests/test_time.rs rename to tests/it/time.rs index 6459f98..1a7597b 100644 --- a/tests/test_time.rs +++ b/tests/it/time.rs @@ -8,12 +8,10 @@ use time::{macros::datetime, Date, OffsetDateTime}; use clickhouse::Row; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn datetime() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)] struct MyRow { @@ -116,10 +114,10 @@ async fn datetime() { assert_eq!(row_str.dt64ns, &original_row.dt64ns.to_string()[..29]); } -#[common::named] +#[crate::named] #[tokio::test] async fn date() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, Serialize, Deserialize, Row)] struct MyRow { @@ -170,10 +168,10 @@ async fn date() { } } -#[common::named] +#[crate::named] #[tokio::test] async fn date32() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, Serialize, Deserialize, Row)] struct MyRow { diff --git a/tests/test_uuid.rs b/tests/it/uuid.rs similarity index 94% rename from tests/test_uuid.rs rename to tests/it/uuid.rs index eb12483..fbc196b 100644 --- a/tests/test_uuid.rs +++ b/tests/it/uuid.rs @@ -5,12 +5,10 @@ use uuid::Uuid; use clickhouse::Row; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn smoke() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)] struct MyRow { diff --git a/tests/test_wa_37420.rs b/tests/it/wa_37420.rs similarity index 95% rename from tests/test_wa_37420.rs rename to tests/it/wa_37420.rs index 9851b8f..26d92e6 100644 --- a/tests/test_wa_37420.rs +++ b/tests/it/wa_37420.rs @@ -4,12 +4,10 @@ use serde::{Deserialize, Serialize}; use clickhouse::Row; -mod common; - -#[common::named] +#[crate::named] #[tokio::test] async fn smoke() { - let client = common::prepare_database!(); + let client = prepare_database!(); #[derive(Debug, Row, Serialize, Deserialize)] pub struct Row { diff --git a/tests/test_watch.rs b/tests/it/watch.rs similarity index 95% rename from tests/test_watch.rs rename to tests/it/watch.rs index e42d843..ffb139b 100644 --- a/tests/test_watch.rs +++ b/tests/it/watch.rs @@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize}; use clickhouse::{Client, Row}; -mod common; - #[derive(Debug, PartialEq, Row, Serialize, Deserialize)] struct MyRow { num: u32, @@ -33,10 +31,10 @@ async fn insert_into_table(client: &Client, rows: &[MyRow]) { insert.end().await.unwrap(); } -#[common::named] +#[crate::named] #[tokio::test] async fn changes() { - let client = common::prepare_database!(); + let client = prepare_database!(); create_table(&client).await; @@ -71,10 +69,10 @@ async fn changes() { assert_eq!(cursor2.next().await.unwrap(), Some((3, MyRow { num: 21 }))); } -#[common::named] +#[crate::named] #[tokio::test] async fn events() { - let client = common::prepare_database!(); + let client = prepare_database!(); create_table(&client).await;