vmexec 0.2.0

Run a single command in a speedy virtual machine with zero-setup
use std::{process::Command, thread::sleep, time::Duration};

use assert_cmd::prelude::*;
use color_eyre::Result;
use predicates::str::contains;

/// Run ps and exit
#[test]
fn ps_command() -> Result<()> {
    Command::cargo_bin("vmexec")?
        .arg("ps")
        .assert()
        .success()
        .stdout(contains("VM ID"));

    Ok(())
}

/// Run a detached VM and run a command in it
#[test]
fn exec_command() -> Result<()> {
    let detached_run_output = Command::cargo_bin("vmexec")?
        .arg("run")
        .arg("archlinux")
        .arg("--detach")
        .arg("--disable-kvm")
        .args(["--ssh-timeout", "300"])
        .args(["sleep", "300"])
        .assert()
        .success()
        .get_output()
        .stdout
        .clone();
    let detached_run_output_str = String::from_utf8(detached_run_output)?;
    let detached_vm_id = detached_run_output_str.lines().last().unwrap();

    sleep(Duration::from_secs(10));

    Command::cargo_bin("vmexec")?
        .arg("exec")
        .arg(detached_vm_id)
        .args(["echo", "test in running vm"])
        .assert()
        .success()
        .stdout(contains("test in running vm"));

    Command::cargo_bin("vmexec")?
        .arg("stop")
        .arg(detached_vm_id)
        .assert()
        .success();

    Ok(())
}

/// Run a basic command and exit
#[test]
fn run_command() -> Result<()> {
    Command::cargo_bin("vmexec")?
        .arg("run")
        .arg("archlinux")
        .arg("--disable-kvm")
        .args(["--ssh-timeout", "300"])
        .args(["echo", "hello yes"])
        .assert()
        .success()
        .stdout(contains("hello yes"));

    Ok(())
}