mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-12 17:32:21 -04:00
Merge steamos-workerd in
This commit is contained in:
parent
6f1f1c032c
commit
83e9de9bcb
10 changed files with 1445 additions and 139 deletions
47
src/testing.rs
Normal file
47
src/testing.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
|
||||
thread_local! {
|
||||
static TEST: RefCell<Option<Rc<Test>>> = RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn start() -> TestHandle {
|
||||
TEST.with(|lock| {
|
||||
assert!(lock.borrow().as_ref().is_none());
|
||||
let test: Rc<Test> = Rc::new(Test {
|
||||
base: tempdir().expect("Couldn't create test directory"),
|
||||
});
|
||||
*lock.borrow_mut() = Some(test.clone());
|
||||
TestHandle { test }
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stop() {
|
||||
TEST.with(|lock| *lock.borrow_mut() = None);
|
||||
}
|
||||
|
||||
pub fn current() -> Rc<Test> {
|
||||
TEST.with(|lock| lock.borrow().as_ref().unwrap().clone())
|
||||
}
|
||||
|
||||
pub struct Test {
|
||||
base: TempDir,
|
||||
}
|
||||
|
||||
pub struct TestHandle {
|
||||
pub test: Rc<Test>,
|
||||
}
|
||||
|
||||
impl Test {
|
||||
pub fn path(&self) -> &Path {
|
||||
self.base.path()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestHandle {
|
||||
fn drop(&mut self) {
|
||||
stop();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue