testcontainers_modules/elasticmq/
mod.rs

1use testcontainers::{core::WaitFor, Image};
2
3const NAME: &str = "softwaremill/elasticmq";
4const TAG: &str = "1.5.2";
5
6#[allow(missing_docs)]
7// not having docs here is currently allowed to address the missing docs problem one place at a time. Helping us by documenting just one of these places helps other devs tremendously
8#[derive(Debug, Default, Clone)]
9pub struct ElasticMq {
10    /// (remove if there is another variable)
11    /// Field is included to prevent this struct to be a unit struct.
12    /// This allows extending functionality (and thus further variables) without breaking changes
13    _priv: (),
14}
15
16impl Image for ElasticMq {
17    fn name(&self) -> &str {
18        NAME
19    }
20
21    fn tag(&self) -> &str {
22        TAG
23    }
24
25    fn ready_conditions(&self) -> Vec<WaitFor> {
26        vec![WaitFor::message_on_stdout("Started SQS rest server")]
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use std::fmt::Display;
33
34    use aws_config::{meta::region::RegionProviderChain, BehaviorVersion};
35    use aws_sdk_sqs::{config::Credentials, Client};
36
37    use crate::{elasticmq::ElasticMq, testcontainers::runners::AsyncRunner};
38
39    #[tokio::test]
40    async fn sqs_list_queues() -> Result<(), Box<dyn std::error::Error + 'static>> {
41        let node = ElasticMq::default().start().await?;
42        let host_ip = node.get_host().await?;
43        let host_port = node.get_host_port_ipv4(9324).await?;
44        let client = build_sqs_client(host_ip, host_port).await;
45
46        let result = client.list_queues().send().await.unwrap();
47        // list should be empty
48        assert!(result.queue_urls.filter(|urls| !urls.is_empty()).is_none());
49        Ok(())
50    }
51
52    async fn build_sqs_client(host_ip: impl Display, host_port: u16) -> Client {
53        let endpoint_uri = format!("http://{host_ip}:{host_port}");
54        let region_provider = RegionProviderChain::default_provider().or_else("us-east-1");
55        let creds = Credentials::new("fakeKey", "fakeSecret", None, None, "test");
56
57        let shared_config = aws_config::defaults(BehaviorVersion::latest())
58            .region(region_provider)
59            .endpoint_url(endpoint_uri)
60            .credentials_provider(creds)
61            .load()
62            .await;
63
64        Client::new(&shared_config)
65    }
66}