1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Supporting types for the `simctl keychain` subcommand.

use super::{Device, Result, Validate};

/// Wrapper around the `simctl keychain` subcommand.
pub struct Keychain {
    device: Device,
}

impl Device {
    /// Returns an instance of the `keychain` subcommand.
    pub fn keychain(&self) -> Keychain {
        Keychain {
            device: self.clone(),
        }
    }
}

impl Keychain {
    /// Resets the device's keychain.
    pub fn reset(&self) -> Result<()> {
        self.device
            .simctl()
            .command("keychain")
            .arg(&self.device.udid)
            .arg("reset")
            .output()?
            .validate()
    }
}

#[cfg(test)]
mod tests {
    use serial_test::serial;

    use super::*;
    use crate::mock;

    #[test]
    #[serial]
    fn test_keychain_reset() -> Result<()> {
        mock::device()?.boot()?;
        mock::device()?.keychain().reset()?;
        mock::device()?.shutdown()?;

        Ok(())
    }
}