Add processor Docker tests

Adds tests/docker for code common to Docker-based tests.
This commit is contained in:
Luke Parker
2023-07-21 14:01:58 -04:00
parent 624fb2781d
commit 523a055b74
13 changed files with 444 additions and 164 deletions

45
tests/docker/src/lib.rs Normal file
View File

@@ -0,0 +1,45 @@
use std::{
sync::{Mutex, OnceLock},
collections::HashMap,
env,
};
static BUILT: OnceLock<Mutex<HashMap<String, bool>>> = OnceLock::new();
pub fn build(name: String) {
let built = BUILT.get_or_init(|| Mutex::new(HashMap::new()));
// Only one call to build will acquire this lock
let mut built_lock = built.lock().unwrap();
if built_lock.contains_key(&name) {
// If it was built, return
return;
}
// Else, hold the lock while we build
let mut path = env::current_exe().unwrap();
path.pop();
assert!(path.as_path().ends_with("deps"));
path.pop();
assert!(path.as_path().ends_with("debug"));
path.pop();
assert!(path.as_path().ends_with("target"));
path.pop();
path.push("deploy");
println!("Building {}...", &name);
assert!(std::process::Command::new("docker")
.current_dir(path)
.arg("compose")
.arg("build")
.arg(&name)
.spawn()
.unwrap()
.wait()
.unwrap()
.success());
println!("Built!");
// Set built
built_lock.insert(name, true);
}