| 1 | |
| 2 | |
| 3 | use std::path::{Path, PathBuf}; |
| 4 | |
| 5 | |
| 6 | |
| 7 | pub struct TestDir(PathBuf); |
| 8 | |
| 9 | impl TestDir { |
| 10 | |
| 11 | pub fn new(name: &str) -> Self { |
| 12 | let path = std::env::temp_dir().join(format!("edith_mcp-test-{name}-{}", std::process::id())); |
| 13 | let _ = std::fs::remove_dir_all(&path); |
| 14 | std::fs::create_dir_all(&path).expect("create test dir"); |
| 15 | Self(path) |
| 16 | } |
| 17 | |
| 18 | pub fn path(&self) -> &Path { |
| 19 | &self.0 |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | impl Drop for TestDir { |
| 24 | fn drop(&mut self) { |
| 25 | let _ = std::fs::remove_dir_all(&self.0); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | impl std::ops::Deref for TestDir { |
| 30 | type Target = Path; |
| 31 | |
| 32 | fn deref(&self) -> &Path { |
| 33 | &self.0 |
| 34 | } |
| 35 | } |