use std::cell::RefCell;
use crate::error::{Error, Result};
use super::VmBackend;
#[derive(Default)]
pub struct MockBackend {
pub active: bool,
pub fail_attach: bool,
pub attaches: RefCell<Vec<String>>,
pub detaches: RefCell<Vec<String>>,
}
impl MockBackend {
pub fn active() -> Self {
MockBackend {
active: true,
..Default::default()
}
}
}
impl VmBackend for MockBackend {
fn is_active(&mut self) -> Result<bool> {
Ok(self.active)
}
fn attach(&mut self, xml: &str) -> Result<()> {
if self.fail_attach {
return Err(Error::libvirt("mock attach failure"));
}
self.attaches.borrow_mut().push(xml.to_string());
Ok(())
}
fn detach(&mut self, xml: &str) -> Result<()> {
self.detaches.borrow_mut().push(xml.to_string());
Ok(())
}
}