creator_simctl/
get_app_container.rs1use std::path::{Path, PathBuf};
4use std::process::Stdio;
5
6use super::{Device, Result, Validate};
7
8#[derive(Clone, Debug, Eq, PartialEq)]
10pub enum Container {
11 App,
14
15 Data,
17
18 Group(String),
22}
23
24impl Device {
25 pub fn get_app_container(&self, bundle_id: &str, container: &Container) -> Result<PathBuf> {
28 let container = match container {
29 Container::App => "app",
30 Container::Data => "data",
31 Container::Group(group) => group,
32 };
33
34 let output = self
35 .simctl()
36 .command("get_app_container")
37 .arg(&self.udid)
38 .arg(bundle_id)
39 .arg(container)
40 .stdout(Stdio::piped())
41 .output()?;
42
43 let output = output.validate_with_output()?;
44
45 Ok(Path::new(String::from_utf8(output.stdout)?.trim()).to_path_buf())
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use serial_test::serial;
52
53 use super::*;
54 use crate::mock;
55
56 #[test]
57 #[serial]
58 fn test_get_app_container() -> Result<()> {
59 mock::device()?.boot()?;
60
61 let path = mock::device()?.get_app_container("com.apple.mobilesafari", &Container::App)?;
62 assert!(path.ends_with(
63 "iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileSafari.app"
64 ));
65 let _ = mock::device()?.get_app_container("com.apple.mobilesafari", &Container::Data);
66
67 mock::device()?.shutdown()?;
68
69 Ok(())
70 }
71}