summaryrefslogtreecommitdiff
path: root/tests/integration/runtime.rs
blob: d5a96352ebaa5b098a64b87b9d7bce809059549c (plain)
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
/// Check if a container runtime (podman or docker) is available and responsive.
pub fn is_container_runtime_available() -> bool {
    for runtime in &["podman", "docker"] {
        if std::process::Command::new(runtime)
            .args(["info"])
            .stdout(std::process::Stdio::null())
            .stderr(std::process::Stdio::null())
            .status()
            .map(|s| s.success())
            .unwrap_or(false)
        {
            return true;
        }
    }
    false
}

/// Macro that skips the current test with an explicit message when
/// no container runtime is available.
///
/// Usage: `skip_without_runtime!();`
macro_rules! skip_without_runtime {
    () => {
        if !crate::runtime::is_container_runtime_available() {
            eprintln!("SKIPPED: no container runtime (podman/docker) found");
            return;
        }
    };
}

/// Macro that skips the current test with an explicit message when
/// git is not available.
macro_rules! skip_without_git {
    () => {
        if !crate::git_helpers::is_git_available() {
            eprintln!("SKIPPED: git not found");
            return;
        }
    };
}

/// Return the name of an available container runtime ("podman" or "docker"),
/// falling back to "podman" when neither is responsive.
pub fn detect_container_runtime() -> &'static str {
    for runtime in &["podman", "docker"] {
        if std::process::Command::new(runtime)
            .args(["info"])
            .stdout(std::process::Stdio::null())
            .stderr(std::process::Stdio::null())
            .status()
            .map(|s| s.success())
            .unwrap_or(false)
        {
            return runtime;
        }
    }
    "podman"
}

pub(crate) use skip_without_git;
pub(crate) use skip_without_runtime;