Skip to content

Commit

Permalink
refactor(test): reorganize integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Sep 27, 2023
1 parent b35d313 commit d6232f1
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 66 deletions.
14 changes: 6 additions & 8 deletions tests/test_compression.rs → tests/it/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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;
}
14 changes: 6 additions & 8 deletions tests/test_cursor_error.rs → tests/it/cursor_error.rs
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions tests/test_ip.rs → tests/it/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions tests/common.rs → tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -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}"));

Expand Down
6 changes: 2 additions & 4 deletions tests/test_nested.rs → tests/it/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 10 additions & 12 deletions tests/test_query.rs → tests/it/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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> {
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 6 additions & 8 deletions tests/test_time.rs → tests/it/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions tests/test_uuid.rs → tests/it/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions tests/test_wa_37420.rs → tests/it/wa_37420.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions tests/test_watch.rs → tests/it/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use serde::{Deserialize, Serialize};

use clickhouse::{Client, Row};

mod common;

#[derive(Debug, PartialEq, Row, Serialize, Deserialize)]
struct MyRow {
num: u32,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit d6232f1

Please sign in to comment.