mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add processor Docker tests
Adds tests/docker for code common to Docker-based tests.
This commit is contained in:
45
tests/docker/src/lib.rs
Normal file
45
tests/docker/src/lib.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user