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
//! `WaitFor` implementation: `NoWait`.

use crate::container::{OperationalContainer, PendingContainer};
use crate::waitfor::{async_trait, WaitFor};
use crate::DockerTestError;

/// The NoWait `WaitFor` implementation for containers.
/// This variant does not wait for anything, resolves immediately.
#[derive(Clone, Debug)]
pub struct NoWait {}

#[async_trait]
impl WaitFor for NoWait {
    async fn wait_for_ready(
        &self,
        container: PendingContainer,
    ) -> Result<OperationalContainer, DockerTestError> {
        Ok(container.into())
    }
}

#[cfg(test)]
mod tests {
    use crate::container::PendingContainer;
    use crate::docker::Docker;
    use crate::waitfor::{NoWait, WaitFor};
    use crate::StartPolicy;

    // Tests that WaitFor implementation for NoWait
    #[tokio::test]
    async fn test_no_wait_returns_ok() {
        let client = Docker::new().unwrap();
        let wait = Box::new(NoWait {});

        let container_name = "this_is_a_name".to_string();
        let id = "this_is_an_id".to_string();
        let handle_key = "this_is_a_handle_key";

        let container = PendingContainer::new(
            &container_name,
            &id,
            handle_key,
            StartPolicy::Relaxed,
            wait.clone(),
            client,
            None,
            None,
        );

        let result = wait.wait_for_ready(container).await;
        assert!(result.is_ok(), "should always return ok with NoWait");

        let container = result.expect("failed to get container");

        assert_eq!(
            container_name,
            container.name(),
            "returned container is not identical"
        );
    }
}