use std::path::{Path, PathBuf};
use std::process::Stdio;
use super::{Device, Result, Validate};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Container {
App,
Data,
Group(String),
}
impl Device {
pub fn get_app_container(&self, bundle_id: &str, container: &Container) -> Result<PathBuf> {
let container = match container {
Container::App => "app",
Container::Data => "data",
Container::Group(group) => group,
};
let output = self
.simctl()
.command("get_app_container")
.arg(&self.udid)
.arg(bundle_id)
.arg(container)
.stdout(Stdio::piped())
.output()?;
let output = output.validate_with_output()?;
Ok(Path::new(String::from_utf8(output.stdout)?.trim()).to_path_buf())
}
}
#[cfg(test)]
mod tests {
use serial_test::serial;
use super::*;
use crate::mock;
#[test]
#[serial]
fn test_get_app_container() -> Result<()> {
mock::device()?.boot()?;
let path = mock::device()?.get_app_container("com.apple.mobilesafari", &Container::App)?;
assert!(path.ends_with(
"iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileSafari.app"
));
let _ = mock::device()?.get_app_container("com.apple.mobilesafari", &Container::Data);
mock::device()?.shutdown()?;
Ok(())
}
}