-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexecutor.rs
More file actions
65 lines (61 loc) · 2.31 KB
/
executor.rs
File metadata and controls
65 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Container Command Executor Trait
//!
//! This module defines the trait that allows decoupled container actions
//! to execute commands inside running containers.
use testcontainers::core::ExecCommand;
use testcontainers::TestcontainersError;
/// Trait for containers that can execute commands inside themselves
///
/// This trait provides a standardized interface for executing commands within
/// running containers, enabling decoupled container actions that don't need
/// to know about the specific container implementation details.
///
/// ## Usage
///
/// Container actions can use this trait to execute commands without being
/// tightly coupled to the container implementation:
///
/// ```rust,no_run
/// use torrust_tracker_deployer_lib::testing::e2e::containers::ContainerExecutor;
/// use testcontainers::core::ExecCommand;
///
/// async fn setup_something<T: ContainerExecutor>(container: &T) -> Result<(), Box<dyn std::error::Error>> {
/// let result = container.exec(ExecCommand::new(["echo", "hello"])).await?;
/// Ok(())
/// }
/// ```
#[allow(async_fn_in_trait)]
pub trait ContainerExecutor {
/// Execute a command inside the container
///
/// # Arguments
///
/// * `command` - The command to execute inside the container
///
/// # Returns
///
/// * `Ok(())` - If the command was executed successfully
/// * `Err(TestcontainersError)` - If the command execution failed
///
/// # Errors
///
/// Returns an error if the command execution fails due to container issues,
/// network problems, or other testcontainers-related errors.
///
/// # Note
///
/// The command execution may succeed even if the command itself fails
/// (returns non-zero exit code). The caller should check the exit code
/// in the returned result if needed.
async fn exec(&self, command: ExecCommand) -> std::result::Result<(), TestcontainersError>;
}
#[cfg(test)]
mod tests {
// Note: ContainerExecutor trait is no longer object-safe due to impl Future return type
// This is expected since async traits can't be used as trait objects without boxing futures
#[test]
fn it_should_define_executor_trait_with_exec_method() {
// Test that trait definition compiles correctly
// The actual implementation will be tested with concrete types
}
}