pub struct MongoDbGuard(/* private fields */);Expand description
The running guard for a MongoDbContainer.
Implementations§
Source§impl MongoDbGuard
impl MongoDbGuard
Sourcepub fn connection_string(&self) -> String
pub fn connection_string(&self) -> String
A mongodb:// connection string for the running container’s test database.
Sourcepub fn replica_set_url(&self) -> String
pub fn replica_set_url(&self) -> String
Alias for Self::connection_string; the container is always a (single-node)
replica set.
Methods from Deref<Target = ContainerGuard>§
Sourcepub fn network(&self) -> Option<&Arc<Network>>
pub fn network(&self) -> Option<&Arc<Network>>
The network this container joined, if any — a module may use this to
resolve a sibling’s alias from the guard itself rather than needing to keep a
separate Network reference around.
Sourcepub fn host(&self) -> &str
pub fn host(&self) -> &str
The host address published ports are reachable on — always loopback.
Sourcepub fn get_mapped_port(&self, guest_port: u16) -> Result<u16, RightsizeError>
pub fn get_mapped_port(&self, guest_port: u16) -> Result<u16, RightsizeError>
The host port guest_port is published on.
Distinguishes two failure causes: if this guard isn’t running (stopped, or never
successfully started), the error says so; if it IS running but guest_port was
never declared via with_exposed_ports, the error says the port isn’t exposed.
Sourcepub async fn logs(&self) -> Result<String, RightsizeError>
pub async fn logs(&self) -> Result<String, RightsizeError>
The full logs captured so far. Requires the container to be running.
Sourcepub async fn exec(&self, cmd: &[&str]) -> Result<ExecResult, RightsizeError>
pub async fn exec(&self, cmd: &[&str]) -> Result<ExecResult, RightsizeError>
Runs cmd inside the running container and returns its exit code and captured
output.
Sourcepub async fn follow_output(
&self,
consumer: impl Fn(String) + Send + Sync + 'static,
) -> Result<FollowHandle, RightsizeError>
pub async fn follow_output( &self, consumer: impl Fn(String) + Send + Sync + 'static, ) -> Result<FollowHandle, RightsizeError>
Streams log lines to consumer as they’re produced. Closing (or dropping) the
returned crate::backend::FollowHandle halts delivery — no further lines
reach consumer afterward, even if the container keeps running.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
True from a successful start() until stop(); false before the first start()
and after.