Skip to content

Commit 8080ed9

Browse files
committed
feat: added connection and connection buildup tests
1 parent 1b7204a commit 8080ed9

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/flow_queue/connection.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,21 @@ pub async fn get_flow_channel(uri: &str) -> FlowChannel {
2121
Err(error) => panic!("Cannot create channel {:?}", error),
2222
}
2323
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use crate::flow_queue::connection::connect;
28+
use testcontainers::core::{IntoContainerPort, WaitFor};
29+
use testcontainers::runners::AsyncRunner;
30+
use testcontainers::GenericImage;
31+
use crate::rabbitmq_container_test;
32+
33+
rabbitmq_container_test!(test_rabbitmq_startup, (|url: String| async move {
34+
println!("RabbitMQ started with the url: {}", url);
35+
}));
36+
37+
rabbitmq_container_test!(test_rabbitmq_connection, (|url: String| async move {
38+
connect(&*url).await;
39+
}));
40+
41+
}

src/flow_store/connection.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
use redis::Client;
22

33
pub fn build_connection(redis_url: String) -> Client {
4-
Client::open(redis_url).unwrap_or_else(|err| {
5-
panic!("Cannot connect to redis instance! Reason: {err}")
6-
})
7-
}
4+
match Client::open(redis_url) {
5+
Ok(client) => client,
6+
Err(con_error) => panic!("{}", con_error),
7+
}
8+
}
9+
10+
#[cfg(test)]
11+
mod tests {
12+
use testcontainers::core::IntoContainerPort;
13+
use testcontainers::runners::AsyncRunner;
14+
use testcontainers::GenericImage;
15+
use testcontainers::core::WaitFor;
16+
use crate::flow_store::connection::build_connection;
17+
use crate::redis_container_test;
18+
19+
redis_container_test!(test_redis_startup, (|url: String| async move {
20+
println!("Redis server started correctly on: {}", url);
21+
}));
22+
23+
redis_container_test!(test_redis_connection, (|url: String| async move {
24+
let result = build_connection(url).get_connection();
25+
assert!(result.is_ok());
26+
}));
27+
}

src/lib.rs

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

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

0 commit comments

Comments
 (0)