Skip to content

feat: add with_network() support to ContainerGuard#226

Merged
joshrotenberg merged 1 commit intomainfrom
feat/container-guard-network
Jan 5, 2026
Merged

feat: add with_network() support to ContainerGuard#226
joshrotenberg merged 1 commit intomainfrom
feat/container-guard-network

Conversation

@joshrotenberg
Copy link
Copy Markdown
Owner

Summary

Implements #219. Adds network support to ContainerGuard for multi-container test scenarios.

New Builder Methods

with_network(name)

Attach the container to a Docker network:

let guard = ContainerGuard::new(RedisTemplate::new("redis"))
    .with_network("test-network")
    .start()
    .await?;

create_network(bool)

Control automatic network creation (default: true):

.with_network("existing-network")
.create_network(false)  // Don't create if missing

remove_network_on_drop(bool)

Clean up the network when the guard drops (default: false):

.with_network("test-network")
.remove_network_on_drop(true)  // Clean up network too

network() getter

Get the configured network name:

assert_eq!(guard.network(), Some("test-network"));

Behavior

  • Network is created with bridge driver if it doesn't exist (and create_network is true)
  • Network cleanup only happens if the guard created the network
  • Network is removed after the container is removed (network must be empty)
  • Template's network config is automatically updated

Testing

  • Added 2 new integration tests
  • Updated unit tests for new options
  • All 762 existing tests continue to pass

Closes #219

- Add with_network() builder method to attach container to a network
- Add create_network option (default: true) to auto-create network
- Add remove_network_on_drop option to clean up network on drop
- Add network() getter to retrieve configured network name
- Network is created with bridge driver if it doesn't exist
- Network cleanup only happens if guard created the network

Closes #219
@joshrotenberg joshrotenberg merged commit 0d14769 into main Jan 5, 2026
11 checks passed
@joshrotenberg joshrotenberg deleted the feat/container-guard-network branch January 5, 2026 23:43
@github-actions github-actions Bot mentioned this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add with_network() support to ContainerGuard

1 participant