From 53256aacaa8a8ec5728334afc20ba2945f829b69 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Tue, 19 Apr 2022 12:46:15 -0400 Subject: Unitype and tests --- src/house.rs | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'src/house.rs') diff --git a/src/house.rs b/src/house.rs index 6159c33..735413e 100644 --- a/src/house.rs +++ b/src/house.rs @@ -30,19 +30,42 @@ pub struct House { /// Hostname pub name: String, /// FQDN or IP address, a way to talk to the house - pub address: Address + pub address: String, + + /// Connection to the House, if available + #[serde(skip)] + con: Option, } impl House { - pub fn new(hostname: String, addr: Address) -> Result { - let mut c = Connect::open(&format!("qemu+ssh://{}/system", addr.to_string()))?; + pub fn new(url: String) -> Result { + let mut c = Connect::open(&url.clone())?; // If the connection succeeds, we've got one! Ok(Self { - name: hostname.clone(), - address: addr + name: c.get_hostname()?, + address: c.get_uri()?, + con: Some(c), }) } + + pub fn inhabitants(&mut self) -> Result, Error> { + match &self.con { + Some(c) => { + let domains = c.list_all_domains(0)?; + + let mut waifus: Vec = Vec::new(); + + for d in domains.iter() { + waifus.push(d.clone().try_into()?); + } + Ok(waifus) + }, + None => { + return Err(Error::Connection("Domain connection was None".to_string())); + } + } + } } #[cfg(test)] @@ -58,4 +81,19 @@ mod test { assert_eq!(String::from("127.0.0.1"), a.to_string()); assert_eq!("example.com".to_string(), d.to_string()); } + + #[test] + fn connect_to_house() { + let h: House = House::new("test:///default".to_string()).unwrap(); + } + + #[test] + fn list_inhabitants() { + let mut h: House = House::new("test:///default".to_string()).unwrap(); + + let empty_vec: Vec = vec![]; + + h.inhabitants().unwrap(); + } + } -- cgit v1.2.3