Skip to content

Commit d0ea118

Browse files
committed
feat: added testcontainers creation macro
1 parent 8080ed9 commit d0ea118

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/container/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#[macro_export]
2+
macro_rules! rabbitmq_container_test {
3+
($test_name:ident, $consumer:expr) => {
4+
5+
#[tokio::test]
6+
async fn $test_name() {
7+
let port: u16 = 5672;
8+
let image_name = "rabbitmq";
9+
let wait_message = "Server startup complete";
10+
11+
let container = GenericImage::new(image_name, "latest")
12+
.with_exposed_port(port.tcp())
13+
.with_wait_for(WaitFor::message_on_stdout(wait_message))
14+
.start()
15+
.await
16+
.unwrap();
17+
18+
let host_port = container.get_host_port_ipv4(port).await.unwrap();
19+
let url = format!("amqp://guest:guest@localhost:{}", host_port);
20+
21+
$consumer(url).await;
22+
}
23+
};
24+
}
25+
26+
#[macro_export]
27+
macro_rules! redis_container_test {
28+
($test_name:ident, $consumer:expr) => {
29+
30+
#[tokio::test]
31+
async fn $test_name() {
32+
let port: u16 = 6379;
33+
let image_name = "redis";
34+
let wait_message = "Ready to accept connections";
35+
36+
let container = GenericImage::new(image_name, "latest")
37+
.with_exposed_port(port.tcp())
38+
.with_wait_for(WaitFor::message_on_stdout(wait_message))
39+
.start()
40+
.await
41+
.unwrap();
42+
43+
let host = container.get_host().await.unwrap();
44+
let host_port = container.get_host_port_ipv4(port).await.unwrap();
45+
let url = format!("redis://{host}:{host_port}");
46+
47+
$consumer(url).await;
48+
}
49+
};
50+
}

0 commit comments

Comments
 (0)