| 1 |
|
| 2 |
|
| 3 |
use super::*; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#[test] |
| 9 |
fn the_write_delegates_to_the_script_that_owns_the_guards() { |
| 10 |
let shown = ImageView { |
| 11 |
choices: Choices::default(), |
| 12 |
cursor: Cursor::new(), |
| 13 |
repo: None, |
| 14 |
candidates: Vec::new(), |
| 15 |
editing: None, |
| 16 |
sequence: None, |
| 17 |
pending_write: None, |
| 18 |
device: None, |
| 19 |
error: None, |
| 20 |
saved: false, |
| 21 |
} |
| 22 |
.write_command("/dev/sdX") |
| 23 |
.display(); |
| 24 |
|
| 25 |
assert!(shown.starts_with("build/build-iso.sh")); |
| 26 |
assert!(shown.contains("--write-only")); |
| 27 |
assert!(shown.contains("--write /dev/sdX")); |
| 28 |
|
| 29 |
assert!(!shown.contains("dd ")); |
| 30 |
assert!(!shown.contains("of=")); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
fn view_with(candidates: &[&str]) -> ImageView { |
| 36 |
ImageView { |
| 37 |
choices: Choices::default(), |
| 38 |
cursor: Cursor::new(), |
| 39 |
repo: None, |
| 40 |
candidates: candidates.iter().map(|key| (*key).to_string()).collect(), |
| 41 |
editing: None, |
| 42 |
sequence: None, |
| 43 |
pending_write: None, |
| 44 |
device: None, |
| 45 |
error: None, |
| 46 |
saved: false, |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
#[test] |
| 54 |
fn cycling_the_pubkey_row_passes_back_through_none() { |
| 55 |
let mut view = view_with(&["/home/max/.ssh/a.pub", "/home/max/.ssh/b.pub"]); |
| 56 |
assert_eq!(view.choices.pubkey, ""); |
| 57 |
|
| 58 |
view.cycle_pubkey(true); |
| 59 |
assert_eq!(view.choices.pubkey, "/home/max/.ssh/a.pub"); |
| 60 |
view.cycle_pubkey(true); |
| 61 |
assert_eq!(view.choices.pubkey, "/home/max/.ssh/b.pub"); |
| 62 |
view.cycle_pubkey(true); |
| 63 |
assert_eq!(view.choices.pubkey, "", "the ring returns to no key"); |
| 64 |
|
| 65 |
|
| 66 |
view.cycle_pubkey(false); |
| 67 |
assert_eq!(view.choices.pubkey, "/home/max/.ssh/b.pub"); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
#[test] |
| 73 |
fn a_typed_path_is_not_lost_to_an_index_it_never_had() { |
| 74 |
let mut view = view_with(&["/home/max/.ssh/a.pub"]); |
| 75 |
view.choices.pubkey = "/elsewhere/key.pub".to_string(); |
| 76 |
view.cycle_pubkey(true); |
| 77 |
assert_eq!(view.choices.pubkey, "/home/max/.ssh/a.pub"); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#[test] |
| 83 |
fn no_candidates_explains_itself() { |
| 84 |
let mut view = view_with(&[]); |
| 85 |
view.cycle_pubkey(true); |
| 86 |
assert_eq!(view.choices.pubkey, ""); |
| 87 |
assert!( |
| 88 |
view.error.as_deref().is_some_and(|e| e.contains("~/.ssh")), |
| 89 |
"{:?}", |
| 90 |
view.error |
| 91 |
); |
| 92 |
} |
| 93 |
|