Skip to content

feat: add ContainerGuardSet for multi-container test management#227

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

feat: add ContainerGuardSet for multi-container test management#227
joshrotenberg merged 1 commit intomainfrom
feat/container-guard-set

Conversation

@joshrotenberg
Copy link
Copy Markdown
Owner

Summary

Implements Issue #220 - ContainerGuardSet for managing multiple containers as a group with coordinated lifecycle.

Features

  • Type-erased storage for heterogeneous template types (Redis, Postgres, etc. in the same set)
  • Shared network support with automatic creation/cleanup
  • Coordinated startup via start_all()
  • Access containers by name via contains() and names()
  • Automatic cleanup on drop with panic handling (keep_on_panic)
  • Builder pattern for configuration

API

use docker_wrapper::testing::ContainerGuardSet;
use docker_wrapper::RedisTemplate;

#[tokio::test]
async fn test_with_multiple_containers() -> Result<(), Box<dyn std::error::Error>> {
    let guards = ContainerGuardSet::new()
        .with_network("test-network")
        .add(RedisTemplate::new("redis-1"))
        .add(RedisTemplate::new("redis-2"))
        .keep_on_panic(true)
        .start_all()
        .await?;

    assert!(guards.contains("redis-1"));
    assert!(guards.contains("redis-2"));
    assert_eq!(guards.network(), Some("test-network"));

    // All containers cleaned up on drop
    Ok(())
}

Implementation Details

  • Uses trait objects (Box<dyn PendingEntryTrait>) for type erasure
  • Stores cleanup functions as boxed closures for Drop implementation
  • Network creation/cleanup coordinated with container lifecycle
  • Sequential startup ensures predictable ordering

Tests

Added 6 new integration tests:

  • test_container_guard_set_basic - two container lifecycle
  • test_container_guard_set_with_shared_network - network sharing
  • test_container_guard_set_empty - edge case handling
  • test_container_guard_set_single_container - single container case
  • test_container_guard_set_network_no_auto_remove - network persistence
  • test_container_guard_set_wait_for_ready_disabled - readiness config

Closes #220

Implements Issue #220 - ContainerGuardSet for managing multiple
containers as a group with coordinated lifecycle.

Features:
- Type-erased storage for heterogeneous template types
- Shared network support with automatic creation/cleanup
- Coordinated startup via start_all()
- Access containers by name via contains() and names()
- Automatic cleanup on drop with panic handling
- Builder pattern for configuration

API:
- ContainerGuardSet::new() returns builder
- Builder.add(template) adds containers
- Builder.with_network() sets shared network
- Builder.keep_on_panic() preserves containers on test failure
- Builder.wait_for_ready() controls readiness checks
- Builder.start_all() starts containers and returns guard set
- GuardSet.contains(name) checks for container
- GuardSet.names() iterates container names
- GuardSet.network() returns shared network name

Closes #220
@joshrotenberg joshrotenberg merged commit daa4146 into main Jan 5, 2026
11 checks passed
@joshrotenberg joshrotenberg deleted the feat/container-guard-set branch January 5, 2026 23:56
@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 ContainerGuardSet for multi-container test management

1 participant