Skip to main content

max / alloy

3.0 KB · 93 lines History Blame Raw
1 //! Tests for [`super`].
2
3 use super::*;
4
5 /// The write goes through the script's own path, with `--write-only` so it
6 /// writes the artifact that already exists rather than rebuilding it.
7 /// Re-deriving this is the disk-eating bug the design note warns about.
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 // Nothing resembling a dd, anywhere.
29 assert!(!shown.contains("dd "));
30 assert!(!shown.contains("of="));
31 }
32
33 /// A view with a known candidate list, so the cycling can be exercised
34 /// without a `~/.ssh` to stand in front of it.
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 /// Empty is a position on the ring, not a state to escape. An image with no
51 /// baked key is the ordinary desktop install, so it has to stay reachable
52 /// once a key has been cycled onto the row.
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 // And backwards, off none onto the last one.
66 view.cycle_pubkey(false);
67 assert_eq!(view.choices.pubkey, "/home/max/.ssh/b.pub");
68 }
69
70 /// A path typed by hand is not one of the candidates, so it reads as the
71 /// empty position rather than panicking on a lookup that finds nothing.
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 /// Nothing to cycle says so, rather than silently doing nothing. An inert
81 /// key reads as the form being broken.
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