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

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Jul 21, 2023

Previously ContainerContext::address_for_port would panic for some failure modes, but return an Option for others.

Given that:

  • the function is only used in tests
  • libcnb-test already leans heavily into the "directly panic rather than make the tests call unwrap/expect everywhere" approach
  • the current Option usage is for when there is a bug in the test (ie: the test author forgot to call ContainerConfig::expose_port)

...then it makes sense to panic instead of returning None.

This avoids the .unwrap() boilerplate on the callers side, and also simplifies a future PR to switch from Bollard to using the Docker CLI (this change is being split out to reduce the size of that PR).

The expect() message doesn't conform to the recommended "expect as precondition" style since the other expect()s in the function do not either. (We can always revisit this as part of the Bollard migration.)

GUS-W-13841481.

Previously `ContainerContext::address_for_port` would panic for some
failure modes, but return an `Option` for others.

Given that:
- the function is only used in tests
- `libcnb-test` already leans heavily into the "directly panic rather than
   make the tests call unwrap/expect everywhere" approach
- the current `Option` usage is for when there is a bug in the test (ie: the
  test author forgot to call `ContainerConfig::expose_port`)

...then it makes sense to panic instead of returning `None`.

This avoids the `.unwrap()` boilerplate on the callers side, and also simplifies
a future PR to switch from Bollard to using the Docker CLI (this change is being
split out to reduce the size of that PR).

The `expect()` message doesn't conform to the recommended "expect as
precondition" style since the other `expect()`s in the function do not either.
(We can always revisit this as part of the Bollard migration.)
@edmorley edmorley force-pushed the edmorley/address-for-port-panic branch from 59fb920 to b8ff73e Compare July 21, 2023 10:02
@edmorley edmorley self-assigned this Jul 21, 2023
@edmorley edmorley marked this pull request as ready for review July 21, 2023 10:07
@edmorley edmorley requested a review from a team as a code owner July 21, 2023 10:07
@edmorley edmorley merged commit ae9d00f into main Jul 21, 2023
4 checks passed
@edmorley edmorley deleted the edmorley/address-for-port-panic branch July 21, 2023 10:12
@edmorley edmorley changed the title Improve the ergonomics of ContainerContext::address_for_port libcnb-test: Improve the ergonomics of ContainerContext::address_for_port Jul 24, 2023
@edmorley edmorley added enhancement New feature or request and removed enhancement New feature or request labels Jul 27, 2023
@edmorley edmorley linked an issue Aug 17, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing UX when using address_for_port on a container that's crashed
2 participants