team-ljyzipelo

공개
218줄7.3 KB
1#[test]
2fn extraction_completion_matches_actual_worker_selection_matrix() {
3 use std::collections::BTreeSet;
4
5 fn contents(root: &Path) -> BTreeSet<String> {
6 fn visit(root: &Path, current: &Path, found: &mut BTreeSet<String>) {
7 for entry in fs::read_dir(current).unwrap() {
8 let path = entry.unwrap().path();
9 found.insert(
10 path.strip_prefix(root)
11 .unwrap()
12 .to_str()
13 .unwrap()
14 .replace('\\', "/"),
15 );
16 if path.is_dir() {
17 visit(root, &path, found);
18 }
19 }
20 }
21 let mut found = BTreeSet::new();
22 visit(root, root, &mut found);
23 found
24 }
25
26 let scratch = Scratch::new();
27 let docs = make_directory(&scratch.path("docs"));
28 fs::create_dir(docs.join("empty")).unwrap();
29 fs::create_dir(docs.join("nested")).unwrap();
30 fs::write(docs.join("nested/one.txt"), b"nested content").unwrap();
31 let root_file = scratch.path("root.txt");
32 fs::write(&root_file, b"root content").unwrap();
33 let archive = scratch.path("selection.zip");
34 let (factory, observed) = observed_factory();
35 let mut screen = Screen::new(factory);
36 screen.app.add_sources(vec![docs, root_file]);
37 screen.render(vec![]);
38 screen.set_text("zip-name", "selection.zip");
39 screen.click("만들기");
40 screen.settle();
41
42 let cases: [(&str, Option<&[&str]>, &[&str]); 6] = [
43 (
44 "all",
45 None,
46 &[
47 "docs",
48 "docs/empty",
49 "docs/nested",
50 "docs/nested/one.txt",
51 "root.txt",
52 ],
53 ),
54 (
55 "files",
56 Some(&["docs/nested/one.txt", "root.txt"]),
57 &["docs", "docs/nested", "docs/nested/one.txt", "root.txt"],
58 ),
59 ("directory", Some(&["docs"]), &["docs"]),
60 (
61 "mixed",
62 Some(&["docs", "docs/nested/one.txt"]),
63 &["docs", "docs/nested", "docs/nested/one.txt"],
64 ),
65 ("empty", Some(&["docs/empty"]), &["docs", "docs/empty"]),
66 (
67 "nested-directory",
68 Some(&["docs/nested"]),
69 &["docs", "docs/nested"],
70 ),
71 ];
72 for (name, selected, expected) in cases {
73 screen.open(&archive);
74 let ids = selected.map(|names| {
75 names
76 .iter()
77 .map(|name| {
78 screen
79 .app
80 .model
81 .entries
82 .iter()
83 .find(|entry| entry.name.trim_end_matches('/') == *name)
84 .unwrap_or_else(|| panic!("목록 항목 누락: {name}"))
85 .id
86 })
87 .collect::<BTreeSet<_>>()
88 });
89 if let Some(ids) = &ids {
90 screen.app.model.selected = ids.clone();
91 screen.click("선택한 항목만 풀기");
92 }
93 let output = make_directory(&scratch.path(name));
94 screen.extract(&output);
95 let terminal = screen.app.model.terminal.as_ref().unwrap();
96 assert_eq!(terminal.outcome, Outcome::Completed, "{name}");
97 assert!(screen.app.model.confirmed, "{name}");
98 assert!(terminal.error.is_none(), "{name}");
99 let expected = expected
100 .iter()
101 .map(|name| name.to_string())
102 .collect::<BTreeSet<_>>();
103 assert_eq!(contents(&output), expected, "{name}");
104 let reports = screen
105 .app
106 .model
107 .outputs
108 .iter()
109 .map(|(name, disposition)| {
110 assert_eq!(*disposition, Disposition::Created);
111 name.clone()
112 })
113 .collect::<BTreeSet<_>>();
114 assert_eq!(reports, expected, "{name}");
115 assert_eq!(terminal.created_count as usize, expected.len(), "{name}");
116 for (path, bytes) in [
117 ("docs/nested/one.txt", b"nested content".as_slice()),
118 ("root.txt", b"root content".as_slice()),
119 ] {
120 if expected.contains(path) {
121 assert_eq!(fs::read(output.join(path)).unwrap(), bytes, "{name}");
122 }
123 }
124 match observed.borrow().starts.last().unwrap() {
125 Start::Extract { selection, .. } => match (selection, &ids) {
126 (Selection::All, None) => {}
127 (Selection::EntryIds(actual), Some(ids)) => {
128 assert_eq!(actual, &ids.iter().copied().collect::<Vec<_>>(), "{name}");
129 }
130 _ => panic!("요청 선택 범위 불일치: {name}"),
131 },
132 _ => panic!("추출 요청 누락: {name}"),
133 }
134 let shown = screen.render(vec![]);
135 assert!(
136 shown.iter().any(|(text, _)| text == "압축을 풀었습니다"),
137 "{name}: {shown:?}"
138 );
139 assert!(
140 !shown
141 .iter()
142 .any(|(text, _)| text.contains("저장이 끝났는지") || text.contains("일부 파일만")),
143 "{name}"
144 );
145 screen.click("확인");
146 }
147 assert_reaped(&observed);
148}
149
150#[cfg(unix)]
151#[test]
152fn auto_destination_is_private_under_desktop_umask() {
153 use std::{os::unix::fs::PermissionsExt, process::Command};
154
155 const CHILD: &str = "ZIPELO_PRIVATE_DESTINATION_CHILD";
156 if std::env::var_os(CHILD).is_none() {
157 let output = Command::new("sh")
158 .args([
159 "-c",
160 "umask 0002; exec \"$@\"",
161 "zipelo-private-destination",
162 ])
163 .arg(std::env::current_exe().unwrap())
164 .args([
165 "--exact",
166 "screen::auto_destination_is_private_under_desktop_umask",
167 "--nocapture",
168 ])
169 .env(CHILD, "1")
170 .output()
171 .unwrap();
172 assert!(
173 output.status.success(),
174 "umask 0002 추출 회귀 실패: {}{}",
175 String::from_utf8_lossy(&output.stdout),
176 String::from_utf8_lossy(&output.stderr)
177 );
178 return;
179 }
180
181 let mask = Command::new("sh").args(["-c", "umask"]).output().unwrap();
182 assert_eq!(String::from_utf8(mask.stdout).unwrap().trim(), "0002");
183 let scratch = Scratch::new();
184 let archive = scratch.path("sample.zip");
185 fs::copy(
186 Path::new(env!("CARGO_MANIFEST_DIR"))
187 .join("../../tests/rust-app-real-worker/fixtures/sample.zip"),
188 &archive,
189 )
190 .unwrap();
191 let output = scratch.path("sample");
192 assert!(!output.exists());
193 let (factory, observed) = observed_factory();
194 let mut screen = Screen::new(factory);
195 screen.open(&archive);
196 screen.click("풀기");
197 assert!(screen.app.model.busy());
198 screen.settle();
199 assert_eq!(
200 fs::metadata(&output).unwrap().permissions().mode() & 0o777,
201 0o700
202 );
203 assert_eq!(
204 fs::read(output.join("content.txt")).unwrap(),
205 b"Zipelo real worker flow\n"
206 );
207 assert_eq!(
208 screen.app.model.terminal.as_ref().unwrap().publication,
209 Publication::Complete
210 );
211 assert!(
212 screen
213 .render(vec![])
214 .iter()
215 .any(|(text, _)| text == "압축을 풀었습니다")
216 );
217 assert_reaped(&observed);
218}