testcontainers_modules/mosquitto/mod.rs
1use std::borrow::Cow;
2
3use testcontainers::{core::WaitFor, Image};
4
5const NAME: &str = "eclipse-mosquitto";
6const TAG: &str = "2.0.18";
7
8/// Module to work with [`Mosquitto`] inside of tests.
9///
10/// Starts a MQTT broker without authentication.
11///
12///
13/// # Example
14/// ```
15/// use testcontainers_modules::{mosquitto, testcontainers::runners::SyncRunner};
16///
17/// let mosquitto_instance = mosquitto::Mosquitto::default().start().unwrap();
18///
19/// let broker_url = format!(
20/// "{}:{}",
21/// mosquitto_instance.get_host().unwrap(),
22/// mosquitto_instance.get_host_port_ipv4(1883).unwrap()
23/// );
24/// ```
25///
26/// [`Mosquitto`]: https://mosquitto.org/
27/// [`Mosquitto docker image`]: https://hub.docker.com/_/eclipse-mosquitto
28#[derive(Debug, Default, Clone)]
29pub struct Mosquitto {
30 /// (remove if there is another variable)
31 /// Field is included to prevent this struct to be a unit struct.
32 /// This allows extending functionality (and thus further variables) without breaking changes
33 _priv: (),
34}
35
36impl Image for Mosquitto {
37 fn name(&self) -> &str {
38 NAME
39 }
40
41 fn tag(&self) -> &str {
42 TAG
43 }
44
45 fn ready_conditions(&self) -> Vec<WaitFor> {
46 vec![WaitFor::message_on_stderr(format!(
47 "mosquitto version {TAG} running",
48 ))]
49 }
50
51 fn cmd(&self) -> impl IntoIterator<Item = impl Into<Cow<'_, str>>> {
52 ["mosquitto", "-c", "/mosquitto-no-auth.conf"]
53 }
54}