Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcnb-test: Improve the ergonomics of ContainerContext::address_for_port #605

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ separate changelogs for each crate were used. If you need to refer to these old

### Changed

- `libcnb-test`: `ContainerContext::address_for_port` now returns `SocketAddr` directly instead of `Option<SocketAddr>`. ([#605](https://github.com/heroku/libcnb.rs/pull/605))
- `libcnb-package`: buildpack target directory now contains the target triple. Users that implicitly rely on the output directory need to adapt. The output of `cargo
libcnb package` will refer to the new locations. ([#580](https://github.com/heroku/libcnb.rs/pull/580))
- `libherokubuildpack`: Switch the `flate2` decompression backend from `miniz_oxide` to `zlib`. ([#593](https://github.com/heroku/libcnb.rs/pull/593))
Expand Down
2 changes: 1 addition & 1 deletion examples/ruby-sample/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn basic() {

assert_eq!(
call_test_fixture_service(
container.address_for_port(TEST_PORT).unwrap(),
container.address_for_port(TEST_PORT),
"Hello World!"
)
.unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn starting_web_server_container() {
.env("PORT", TEST_PORT.to_string())
.expose_port(TEST_PORT),
|container| {
let address_on_host = container.address_for_port(TEST_PORT).unwrap();
let address_on_host = container.address_for_port(TEST_PORT);
let url = format!("http://{}:{}", address_on_host.ip(), address_on_host.port());

// Give the server time to start.
Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/src/container_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ContainerConfig {
/// context.start_container(
/// ContainerConfig::new().env("PORT", "12345").expose_port(12345),
/// |container| {
/// let address_on_host = container.address_for_port(12345).unwrap();
/// let address_on_host = container.address_for_port(12345);
/// // ...
/// },
/// );
Expand Down
10 changes: 8 additions & 2 deletions libcnb-test/src/container_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,20 @@ impl<'a> ContainerContext<'a> {
/// context.start_container(
/// ContainerConfig::new().env("PORT", "12345").expose_port(12345),
/// |container| {
/// let address_on_host = container.address_for_port(12345).unwrap();
/// let address_on_host = container.address_for_port(12345);
/// // ...
/// },
/// );
/// },
/// );
/// ```
///
/// # Panics
///
/// Will panic if there was an error obtaining the container port mapping, or the specified port
/// was not exposed using [`ContainerConfig::expose_port`](crate::ContainerConfig::expose_port).
#[must_use]
pub fn address_for_port(&self, port: u16) -> Option<SocketAddr> {
pub fn address_for_port(&self, port: u16) -> SocketAddr {
self.test_context.runner.tokio_runtime.block_on(async {
self.test_context
.runner
Expand All @@ -137,6 +142,7 @@ impl<'a> ContainerContext<'a> {
.get(&port)
.copied()
})
.expect("Could not find specified port in container port mapping")
})
}

Expand Down
2 changes: 1 addition & 1 deletion libcnb-test/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn starting_containers() {
.env("PORT", TEST_PORT.to_string())
.expose_port(TEST_PORT),
|container| {
let address_on_host = container.address_for_port(TEST_PORT).unwrap();
let address_on_host = container.address_for_port(TEST_PORT);
let url = format!("http://{}:{}", address_on_host.ip(), address_on_host.port());

// Retries needed since the server takes a moment to start up.
Expand Down