diff --git a/Cargo.lock b/Cargo.lock index 064083b06..ebd29b4b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)", "credibility 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ssh2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "vmm 0.1.0", diff --git a/Cargo.toml b/Cargo.toml index 7585aaa5d..c49002bd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ ssh2 = "=0.3.3" dirs = "2.0.0" credibility = "0.1.3" tempdir="0.3.7" +lazy_static=">=1.1.0" [features] default = [] diff --git a/src/main.rs b/src/main.rs index 7192f2341..02bd1f5a5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -152,6 +152,11 @@ fn main() { #[macro_use] extern crate credibility; +#[cfg(test)] +#[cfg(feature = "integration_tests")] +#[macro_use] +extern crate lazy_static; + #[cfg(test)] #[cfg(feature = "integration_tests")] mod tests { @@ -161,9 +166,14 @@ mod tests { use std::net::TcpStream; use std::process::Command; use std::string::String; + use std::sync::Mutex; use std::thread; use tempdir::TempDir; + lazy_static! { + static ref NEXT_VM_ID: Mutex = Mutex::new(1); + } + struct Guest { tmp_dir: TempDir, disks: Vec, @@ -206,13 +216,17 @@ mod tests { fn new() -> Self { let tmp_dir = TempDir::new("ch").unwrap(); + let mut guard = NEXT_VM_ID.lock().unwrap(); + let id = *guard; + *guard = id + 1; + let mut guest = Guest { tmp_dir, disks: Vec::new(), fw_path: String::new(), - guest_ip: String::from("192.168.2.2"), - host_ip: String::from("192.168.2.1"), - guest_mac: String::from("12:34:56:78:90:ab"), + guest_ip: format!("192.168.{}.2", id), + host_ip: format!("192.168.{}.1", id), + guest_mac: format!("12:34:56:78:90:{:02x}", id), }; guest.prepare_files();