Skip to content

Commit d712f72

Browse files
committed
feat(sync, network): add support for connect & disconnect
1 parent 691ffc2 commit d712f72

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

testcontainers/src/core/containers/sync_container.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{fmt, io::BufRead, net::IpAddr, sync::Arc};
22

33
use crate::{
4-
core::{env, error::Result, ports::Ports, ContainerPort, ExecCommand},
4+
core::{env, error::Result, network::Network, ports::Ports, ContainerPort, ExecCommand},
55
ContainerAsync, Image,
66
};
77

@@ -64,6 +64,44 @@ impl<I> Container<I>
6464
where
6565
I: Image,
6666
{
67+
// /// Removes the container.
68+
// pub fn rm(mut self) -> Result<()> {
69+
// if let Some(active) = self.inner.take() {
70+
// active.runtime.block_on(active.async_impl.rm())?;
71+
// }
72+
// Ok(())
73+
// }
74+
75+
/// Connect the container to `network`.
76+
pub fn connect(&mut self, network: Option<Arc<Network>>) -> Result<()> {
77+
if let Some(mut active) = self.inner.take() {
78+
active
79+
.runtime
80+
.block_on(active.async_impl.connect(network))?;
81+
}
82+
Ok(())
83+
}
84+
85+
/// Disconnect the container from the network `name`.
86+
pub fn disconnect(&mut self, name: &str) -> Result<()> {
87+
if let Some(mut active) = self.inner.take() {
88+
active
89+
.runtime
90+
.block_on(active.async_impl.disconnect(name))?;
91+
}
92+
Ok(())
93+
}
94+
95+
/// Force the container to disconnect from the network `ǹame`
96+
pub fn force_disconnect(&mut self, name: &str) -> Result<()> {
97+
if let Some(mut active) = self.inner.take() {
98+
active
99+
.runtime
100+
.block_on(active.async_impl.force_disconnect(name))?;
101+
}
102+
Ok(())
103+
}
104+
67105
/// Returns the id of this container.
68106
pub fn id(&self) -> &str {
69107
self.async_impl().id()

0 commit comments

Comments
 (0)