Skip to content

Commit c936d1a

Browse files
committed
ref: moved macros into tests itself
1 parent 5bbfc74 commit c936d1a

File tree

4 files changed

+51
-56
lines changed

4 files changed

+51
-56
lines changed

src/container/mod.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/flow_queue/connection.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,30 @@ mod tests {
2828
use testcontainers::runners::AsyncRunner;
2929
use testcontainers::GenericImage;
3030
use crate::flow_queue::connection::build_connection;
31-
use crate::rabbitmq_container_test;
31+
32+
macro_rules! rabbitmq_container_test {
33+
($test_name:ident, $consumer:expr) => {
34+
35+
#[tokio::test]
36+
async fn $test_name() {
37+
let port: u16 = 5672;
38+
let image_name = "rabbitmq";
39+
let wait_message = "Server startup complete";
40+
41+
let container = GenericImage::new(image_name, "latest")
42+
.with_exposed_port(port.tcp())
43+
.with_wait_for(WaitFor::message_on_stdout(wait_message))
44+
.start()
45+
.await
46+
.unwrap();
47+
48+
let host_port = container.get_host_port_ipv4(port).await.unwrap();
49+
let url = format!("amqp://guest:guest@localhost:{}", host_port);
50+
51+
$consumer(url).await;
52+
}
53+
};
54+
}
3255

3356
rabbitmq_container_test!(test_rabbitmq_startup, (|url: String| async move {
3457
println!("RabbitMQ started with the url: {}", url);

src/flow_store/connection.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22
use redis::aio::MultiplexedConnection;
3-
use redis::{Client, RedisResult};
3+
use redis::{Client};
44
use tokio::sync::Mutex;
55

66
pub type FlowStore = Arc<Mutex<Box<MultiplexedConnection>>>;
@@ -29,7 +29,31 @@ mod tests {
2929
use testcontainers::GenericImage;
3030
use testcontainers::core::WaitFor;
3131
use crate::flow_store::connection::build_connection;
32-
use crate::redis_container_test;
32+
33+
macro_rules! redis_container_test {
34+
($test_name:ident, $consumer:expr) => {
35+
36+
#[tokio::test]
37+
async fn $test_name() {
38+
let port: u16 = 6379;
39+
let image_name = "redis";
40+
let wait_message = "Ready to accept connections";
41+
42+
let container = GenericImage::new(image_name, "latest")
43+
.with_exposed_port(port.tcp())
44+
.with_wait_for(WaitFor::message_on_stdout(wait_message))
45+
.start()
46+
.await
47+
.unwrap();
48+
49+
let host = container.get_host().await.unwrap();
50+
let host_port = container.get_host_port_ipv4(port).await.unwrap();
51+
let url = format!("redis://{host}:{host_port}");
52+
53+
$consumer(url).await;
54+
}
55+
};
56+
}
3357

3458
redis_container_test!(test_redis_startup, (|url: String| async move {
3559
println!("Redis server started correctly on: {}", url);

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
pub mod flow_store;
33

44
#[cfg(feature = "flow_queue")]
5-
pub mod flow_queue;
6-
7-
pub mod container;
5+
pub mod flow_queue;

0 commit comments

Comments
 (0)