//! Tests for [`super`]. use super::*; /// The write goes through the script's own path, with `--write-only` so it /// writes the artifact that already exists rather than rebuilding it. /// Re-deriving this is the disk-eating bug the design note warns about. #[test] fn the_write_delegates_to_the_script_that_owns_the_guards() { let shown = ImageView { choices: Choices::default(), cursor: Cursor::new(), repo: None, candidates: Vec::new(), editing: None, sequence: None, pending_write: None, device: None, error: None, saved: false, } .write_command("/dev/sdX") .display(); assert!(shown.starts_with("build/build-iso.sh")); assert!(shown.contains("--write-only")); assert!(shown.contains("--write /dev/sdX")); // Nothing resembling a dd, anywhere. assert!(!shown.contains("dd ")); assert!(!shown.contains("of=")); } /// A view with a known candidate list, so the cycling can be exercised /// without a `~/.ssh` to stand in front of it. fn view_with(candidates: &[&str]) -> ImageView { ImageView { choices: Choices::default(), cursor: Cursor::new(), repo: None, candidates: candidates.iter().map(|key| (*key).to_string()).collect(), editing: None, sequence: None, pending_write: None, device: None, error: None, saved: false, } } /// Empty is a position on the ring, not a state to escape. An image with no /// baked key is the ordinary desktop install, so it has to stay reachable /// once a key has been cycled onto the row. #[test] fn cycling_the_pubkey_row_passes_back_through_none() { let mut view = view_with(&["/home/max/.ssh/a.pub", "/home/max/.ssh/b.pub"]); assert_eq!(view.choices.pubkey, ""); view.cycle_pubkey(true); assert_eq!(view.choices.pubkey, "/home/max/.ssh/a.pub"); view.cycle_pubkey(true); assert_eq!(view.choices.pubkey, "/home/max/.ssh/b.pub"); view.cycle_pubkey(true); assert_eq!(view.choices.pubkey, "", "the ring returns to no key"); // And backwards, off none onto the last one. view.cycle_pubkey(false); assert_eq!(view.choices.pubkey, "/home/max/.ssh/b.pub"); } /// A path typed by hand is not one of the candidates, so it reads as the /// empty position rather than panicking on a lookup that finds nothing. #[test] fn a_typed_path_is_not_lost_to_an_index_it_never_had() { let mut view = view_with(&["/home/max/.ssh/a.pub"]); view.choices.pubkey = "/elsewhere/key.pub".to_string(); view.cycle_pubkey(true); assert_eq!(view.choices.pubkey, "/home/max/.ssh/a.pub"); } /// Nothing to cycle says so, rather than silently doing nothing. An inert /// key reads as the form being broken. #[test] fn no_candidates_explains_itself() { let mut view = view_with(&[]); view.cycle_pubkey(true); assert_eq!(view.choices.pubkey, ""); assert!( view.error.as_deref().is_some_and(|e| e.contains("~/.ssh")), "{:?}", view.error ); }