use crate::{
composition::{LogOptions, StaticManagementPolicy},
container::OperationalContainer,
docker::{ContainerState, Docker},
waitfor::WaitFor,
DockerTestError, StartPolicy,
};
#[derive(Clone)]
pub struct PendingContainer {
pub(crate) client: Docker,
pub(crate) name: String,
pub(crate) id: String,
pub(crate) handle: String,
pub(crate) start_policy: StartPolicy,
pub(crate) wait: Option<Box<dyn WaitFor>>,
pub(crate) is_static: bool,
pub(crate) static_management_policy: Option<StaticManagementPolicy>,
pub(crate) log_options: Option<LogOptions>,
pub(crate) expected_state: ContainerState,
}
impl PendingContainer {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new<T: ToString, R: ToString, H: ToString>(
name: T,
id: R,
handle: H,
start_policy: StartPolicy,
wait: Box<dyn WaitFor>,
client: Docker,
static_management_policy: Option<StaticManagementPolicy>,
log_options: Option<LogOptions>,
) -> PendingContainer {
PendingContainer {
client,
name: name.to_string(),
id: id.to_string(),
handle: handle.to_string(),
start_policy,
is_static: static_management_policy.is_some(),
static_management_policy,
log_options,
expected_state: wait.expected_state(),
wait: Some(wait),
}
}
pub(crate) async fn start(self) -> Result<OperationalContainer, DockerTestError> {
let client = self.client.clone();
client.start_container(self).await
}
pub(crate) async fn start_inner(self) -> Result<OperationalContainer, DockerTestError> {
let client = self.client.clone();
client.start_container_inner(self).await
}
}
#[cfg(test)]
mod tests {
use crate::container::PendingContainer;
use crate::docker::Docker;
use crate::waitfor::NoWait;
use crate::StartPolicy;
#[tokio::test]
async fn test_new_pending_container() {
let client = Docker::new().unwrap();
let id = "this_is_an_id".to_string();
let name = "this_is_a_container_name".to_string();
let handle_key = "this_is_a_handle_key";
let container = PendingContainer::new(
&name,
&id,
handle_key,
StartPolicy::Relaxed,
Box::new(NoWait {}),
client,
None,
None,
);
assert_eq!(id, container.id, "wrong id set in container creation");
assert_eq!(name, container.name, "wrong name set in container creation");
assert_eq!(
name, container.name,
"container name getter returns wrong value"
);
assert_eq!(
handle_key, container.handle,
"wrong handle_key set in container creation"
);
}
}