use std::env;
use std::path::PathBuf;
use tempfile::TempDir;
use vx_plugin::PluginRegistry;
pub struct CliTestFixture {
pub temp_dir: TempDir,
pub original_dir: PathBuf,
}
impl CliTestFixture {
pub fn new() -> anyhow::Result<Self> {
let temp_dir = TempDir::new()?;
let original_dir = env::current_dir()?;
env::set_current_dir(temp_dir.path())?;
Ok(Self {
temp_dir,
original_dir,
})
}
pub fn path(&self) -> &std::path::Path {
self.temp_dir.path()
}
pub fn create_file(&self, name: &str, content: &str) -> anyhow::Result<()> {
std::fs::write(self.path().join(name), content)?;
Ok(())
}
}
impl Drop for CliTestFixture {
fn drop(&mut self) {
let _ = env::set_current_dir(&self.original_dir);
}
}
pub fn create_test_env_dir() -> anyhow::Result<TempDir> {
let temp_dir = TempDir::new()?;
Ok(temp_dir)
}
pub fn create_test_registry() -> PluginRegistry {
PluginRegistry::new()
}
pub fn cleanup_test_env() {
}
pub mod sample_configs {
pub const SAMPLE_VX_CONFIG: &str = r#"
[tools]
node = "18.17.0"
python = "3.11.5"
[settings]
auto_install = true
"#;
}