Skip to content

Commit

Permalink
Adding ExposedPorts to hold the internet protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
estigma88 committed Jun 13, 2024
1 parent 85e05fa commit 1a235be
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
3 changes: 1 addition & 2 deletions testcontainers/src/core/containers/async_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ use crate::{
macros,
network::Network,
ports::Ports,
ContainerState, ExecCommand, WaitFor,
ContainerState, ExecCommand, WaitFor, ExposedPort
},
ContainerRequest, Image,
};
use crate::core::ports::ExposedPort;

pub(super) mod exec;

Expand Down
3 changes: 1 addition & 2 deletions testcontainers/src/core/containers/sync_container.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::{fmt, io::BufRead, net::IpAddr, sync::Arc};

use crate::{
core::{env, error::Result, ports::Ports, ExecCommand},
core::{env, error::Result, ports::Ports, ExecCommand, ExposedPort},
ContainerAsync, Image,
};
use crate::core::ports::ExposedPort;

pub(super) mod exec;
mod sync_reader;
Expand Down
3 changes: 1 addition & 2 deletions testcontainers/src/core/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::error::Error;

use crate::core::logs::WaitLogError;
pub use crate::core::{client::ClientError, env::ConfigurationError};
use crate::core::ports::ExposedPort;
pub use crate::core::{client::ClientError, env::ConfigurationError, ExposedPort};

pub type Result<T> = std::result::Result<T, TestcontainersError>;

Expand Down
3 changes: 1 addition & 2 deletions testcontainers/src/runners/async_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ impl From<CgroupnsMode> for HostConfigCgroupnsModeEnum {
#[cfg(test)]
mod tests {
use super::*;
use crate::{core::WaitFor, images::generic::GenericImage, ImageExt};
use crate::core::ports::ExposedPort;
use crate::{core::{WaitFor, ExposedPort}, images::generic::GenericImage, ImageExt};

#[tokio::test]
async fn async_run_command_should_expose_all_ports_if_no_explicit_mapping_requested(
Expand Down
14 changes: 7 additions & 7 deletions testcontainers/src/runners/sync_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use crate::{core::error::Result, Container, ContainerRequest, Image};
/// ## Example
///
/// ```rust,no_run
/// use testcontainers::{core::WaitFor, runners::SyncRunner, GenericImage};
/// use testcontainers::{core::{WaitFor, ExposedPort}, runners::SyncRunner, GenericImage};
///
/// fn test_redis() {
/// let container = GenericImage::new("redis", "7.2.4")
/// .with_exposed_port(6379)
/// .with_exposed_port(ExposedPort::Tcp(6379))
/// .with_wait_for(WaitFor::message_on_stdout("Ready to accept connections"))
/// .start()
/// .unwrap();
Expand Down Expand Up @@ -60,7 +60,7 @@ mod tests {

use super::*;
use crate::{
core::{client::Client, mounts::Mount, WaitFor},
core::{client::Client, mounts::Mount, WaitFor, ExposedPort},
images::generic::GenericImage,
ImageExt,
};
Expand Down Expand Up @@ -134,11 +134,11 @@ mod tests {
#[test]
fn sync_run_command_should_map_exposed_port() -> anyhow::Result<()> {
let image = GenericImage::new("simple_web_server", "latest")
.with_exposed_port(5000)
.with_exposed_port(ExposedPort::Tcp(5000))
.with_wait_for(WaitFor::message_on_stdout("server is ready"))
.with_wait_for(WaitFor::seconds(1));
let container = image.start()?;
let res = container.get_host_port_ipv4(5000);
let res = container.get_host_port_ipv4(ExposedPort::Tcp(5000));
assert!(res.is_ok());
Ok(())
}
Expand All @@ -147,8 +147,8 @@ mod tests {
fn sync_run_command_should_expose_only_requested_ports() -> anyhow::Result<()> {
let image = GenericImage::new("hello-world", "latest");
let container = image
.with_mapped_port((124, 456))
.with_mapped_port((556, 888))
.with_mapped_port((124, ExposedPort::Tcp(456)))
.with_mapped_port((556, ExposedPort::Tcp(888)))
.start()?;

let container_details = inspect(container.id());
Expand Down
3 changes: 1 addition & 2 deletions testcontainers/tests/dual_stack_host_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use std::net::{Ipv6Addr, TcpListener};

use testcontainers::{core::WaitFor, runners::SyncRunner, GenericImage};
use testcontainers::core::ports::ExposedPort;
use testcontainers::{core::{WaitFor, ExposedPort}, runners::SyncRunner, GenericImage};

/// Test the functionality of exposing container ports over both IPv4 and IPv6.
#[test]
Expand Down
3 changes: 1 addition & 2 deletions testcontainers/tests/sync_runner.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![cfg(feature = "blocking")]

use testcontainers::{
core::{CmdWaitFor, ExecCommand, Host, WaitFor},
core::{CmdWaitFor, ExecCommand, Host, WaitFor, ExposedPort},
runners::SyncRunner,
*,
};
use testcontainers::core::ports::ExposedPort;

fn get_server_container(msg: Option<WaitFor>) -> GenericImage {
let msg = msg.unwrap_or(WaitFor::message_on_stdout("server is ready"));
Expand Down

0 comments on commit 1a235be

Please sign in to comment.