Skip to content

Commit

Permalink
refactor(tests): get rid of function_name
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Nov 12, 2023
1 parent 92dd060 commit 843ca7e
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 28 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,5 @@ hyper = { version = "0.14", features = ["client", "tcp", "http1", "stream", "ser
serde_bytes = "0.11.4"
serde_repr = "0.1.7"
uuid = { version = "1", features = ["v4"] }
function_name = "0.3"
time = { version = "0.3.17", features = ["macros", "rand"] }
rand = "0.8.5"
3 changes: 0 additions & 3 deletions tests/it/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,20 @@ async fn check(client: Client) {
assert_eq!(sum_len, 600_000);
}

#[crate::named]
#[tokio::test]
async fn none() {
let client = prepare_database!().with_compression(Compression::None);
check(client).await;
}

#[cfg(feature = "lz4")]
#[crate::named]
#[tokio::test]
async fn lz4() {
let client = prepare_database!().with_compression(Compression::Lz4);
check(client).await;
}

#[cfg(feature = "lz4")]
#[crate::named]
#[tokio::test]
async fn lz4_hc() {
let client = prepare_database!().with_compression(Compression::Lz4Hc(4));
Expand Down
3 changes: 0 additions & 3 deletions tests/it/cursor_error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use clickhouse::{Client, Compression};

#[crate::named]
#[tokio::test]
async fn deferred() {
let client = prepare_database!();
max_execution_time(client, false).await;
}

#[crate::named]
#[tokio::test]
async fn wait_end_of_query() {
let client = prepare_database!();
Expand Down Expand Up @@ -46,7 +44,6 @@ async fn max_execution_time(mut client: Client, wait_end_of_query: bool) {
}

#[cfg(feature = "lz4")]
#[crate::named]
#[tokio::test]
async fn deferred_lz4() {
let client = prepare_database!().with_compression(Compression::Lz4);
Expand Down
1 change: 0 additions & 1 deletion tests/it/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};

use clickhouse::Row;

#[crate::named]
#[tokio::test]
async fn smoke() {
let client = prepare_database!();
Expand Down
25 changes: 17 additions & 8 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use clickhouse::{sql, Client};
use function_name::named;

macro_rules! prepare_database {
() => {
crate::_priv::prepare_database(file!(), function_name!()).await
crate::_priv::prepare_database({
fn f() {}
fn type_name_of_val<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
type_name_of_val(f)
})
.await
};
}

Expand All @@ -21,8 +27,8 @@ const HOST: &str = "localhost:8123";
mod _priv {
use super::*;

pub(crate) async fn prepare_database(file_path: &str, fn_name: &str) -> Client {
let name = make_db_name(file_path, fn_name);
pub(crate) async fn prepare_database(fn_path: &str) -> Client {
let name = make_db_name(fn_path);
let client = Client::default().with_url(format!("http://{HOST}"));

client
Expand All @@ -42,9 +48,12 @@ mod _priv {
client.with_database(name)
}

fn make_db_name(file_path: &str, fn_name: &str) -> String {
let (_, basename) = file_path.rsplit_once('/').expect("invalid file's path");
let prefix = basename.strip_suffix(".rs").expect("invalid file's path");
format!("{prefix}__{fn_name}")
// `it::compression::lz4::{{closure}}::f` -> `chrs__compression__lz4`
fn make_db_name(fn_path: &str) -> String {
assert!(fn_path.starts_with("it::"));
let mut iter = fn_path.split("::").skip(1);
let module = iter.next().unwrap();
let test = iter.next().unwrap();
format!("chrs__{module}__{test}")
}
}
1 change: 0 additions & 1 deletion tests/it/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};

use clickhouse::Row;

#[crate::named]
#[tokio::test]
async fn smoke() {
let client = prepare_database!();
Expand Down
5 changes: 0 additions & 5 deletions tests/it/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};

use clickhouse::{error::Error, Row};

#[crate::named]
#[tokio::test]
async fn smoke() {
let client = prepare_database!();
Expand Down Expand Up @@ -52,7 +51,6 @@ async fn smoke() {
}
}

#[crate::named]
#[tokio::test]
async fn fetch_one_and_optional() {
let client = prepare_database!();
Expand Down Expand Up @@ -88,7 +86,6 @@ async fn fetch_one_and_optional() {
}

// See #19.
#[crate::named]
#[tokio::test]
async fn long_query() {
let client = prepare_database!();
Expand All @@ -112,7 +109,6 @@ async fn long_query() {
}

// See #22.
#[crate::named]
#[tokio::test]
async fn big_borrowed_str() {
let client = prepare_database!();
Expand Down Expand Up @@ -151,7 +147,6 @@ async fn big_borrowed_str() {
}

// See #31.
#[crate::named]
#[tokio::test]
async fn all_floats() {
let client = prepare_database!();
Expand Down
3 changes: 0 additions & 3 deletions tests/it/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use time::{macros::datetime, Date, OffsetDateTime};

use clickhouse::Row;

#[crate::named]
#[tokio::test]
async fn datetime() {
let client = prepare_database!();
Expand Down Expand Up @@ -114,7 +113,6 @@ async fn datetime() {
assert_eq!(row_str.dt64ns, &original_row.dt64ns.to_string()[..29]);
}

#[crate::named]
#[tokio::test]
async fn date() {
let client = prepare_database!();
Expand Down Expand Up @@ -168,7 +166,6 @@ async fn date() {
}
}

#[crate::named]
#[tokio::test]
async fn date32() {
let client = prepare_database!();
Expand Down
1 change: 0 additions & 1 deletion tests/it/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use uuid::Uuid;

use clickhouse::Row;

#[crate::named]
#[tokio::test]
async fn smoke() {
let client = prepare_database!();
Expand Down
2 changes: 0 additions & 2 deletions tests/it/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async fn insert_into_table(client: &Client, rows: &[MyRow]) {
insert.end().await.unwrap();
}

#[crate::named]
#[tokio::test]
async fn changes() {
let client = prepare_database!();
Expand Down Expand Up @@ -69,7 +68,6 @@ async fn changes() {
assert_eq!(cursor2.next().await.unwrap(), Some((3, MyRow { num: 21 })));
}

#[crate::named]
#[tokio::test]
async fn events() {
let client = prepare_database!();
Expand Down

0 comments on commit 843ca7e

Please sign in to comment.