Skip to main content

tank_tests/
lib.rs

1mod aggregates;
2mod ambiguity;
3mod arrays1;
4mod arrays2;
5mod books;
6mod cheat_sheet;
7mod complex;
8mod conditions;
9mod custom;
10mod enums;
11mod identifiers;
12mod insane;
13mod interval;
14mod keywords;
15mod kv_storage;
16mod limits;
17mod math;
18mod metrics;
19mod multiple;
20mod operations;
21mod orders;
22mod other;
23mod readme;
24mod requests;
25mod service;
26mod shopping;
27mod simple;
28mod time;
29mod trade;
30mod transaction1;
31mod transaction2;
32mod user;
33
34pub use aggregates::*;
35pub use ambiguity::*;
36pub use arrays1::*;
37pub use arrays2::*;
38pub use books::*;
39pub use cheat_sheet::*;
40pub use complex::*;
41pub use conditions::*;
42pub use custom::*;
43pub use enums::*;
44pub use identifiers::*;
45pub use insane::*;
46pub use interval::*;
47pub use keywords::*;
48pub use kv_storage::*;
49pub use limits::*;
50use log::LevelFilter;
51pub use math::*;
52pub use metrics::*;
53pub use multiple::*;
54pub use operations::*;
55pub use orders::*;
56pub use other::*;
57pub use readme::*;
58pub use requests::*;
59pub use service::*;
60pub use shopping::*;
61pub use simple::*;
62use std::env;
63use tank::{ConnectionPool, Driver};
64pub use time::*;
65pub use trade::*;
66pub use transaction1::*;
67pub use transaction2::*;
68pub use user::*;
69
70pub fn init_logs() {
71    let mut logger = env_logger::builder();
72    logger
73        .is_test(true)
74        .format_file(true)
75        .format_line_number(true);
76    if env::var("RUST_LOG").is_err() {
77        logger.filter_level(LevelFilter::Warn);
78    }
79    let _ = logger.try_init();
80}
81
82pub async fn execute_tests<D: Driver>(pool: &mut impl ConnectionPool<D>) {
83    let mut connection = pool
84        .get()
85        .await
86        .expect("Could not get a connection from the pool");
87    macro_rules! do_test {
88        ($test_function:ident $(, $args:expr )* $(,)?) => {
89            Box::pin($test_function(&mut connection, $($args),*)).await
90        };
91    }
92    do_test!(simple);
93    do_test!(kv_storage);
94    do_test!(trade_simple);
95    do_test!(trade_multiple);
96    do_test!(users);
97    do_test!(aggregates);
98    do_test!(books);
99    do_test!(complex);
100    do_test!(insane);
101    do_test!(limits);
102    #[cfg(not(feature = "disable-multiple-statements"))]
103    do_test!(multiple);
104    #[cfg(not(feature = "disable-intervals"))]
105    do_test!(interval);
106    #[cfg(not(feature = "disable-arrays"))]
107    do_test!(arrays1);
108    #[cfg(not(feature = "disable-arrays"))]
109    do_test!(arrays2);
110    #[cfg(not(feature = "disable-transactions"))]
111    do_test!(transaction1);
112    #[cfg(not(feature = "disable-transactions"))]
113    do_test!(transaction2);
114    do_test!(shopping);
115    do_test!(orders);
116    do_test!(times);
117    do_test!(conditions);
118    do_test!(metrics);
119    do_test!(math);
120    do_test!(ambiguity);
121    do_test!(other);
122    do_test!(service);
123    do_test!(enums);
124    do_test!(custom);
125    do_test!(requests);
126    do_test!(keywords);
127    do_test!(identifiers);
128    do_test!(readme).expect("Readme examples test did not succeed");
129    do_test!(operations).expect("Operations examples test did not succeed");
130    do_test!(advanced_operations).expect("Advanced operations examples test did not succeed");
131    do_test!(cheat_sheet).expect("Cheat Sheet examples test did not succeed");
132}
133
134#[macro_export]
135macro_rules! silent_logs {
136    ($($code:tt)+) => {{
137        let level = log::max_level();
138        log::set_max_level(log::LevelFilter::Off);
139        $($code)+
140        log::set_max_level(level);
141    }};
142}