| | @@ -0,0 +1,110 @@ |
| 1 | +추가: use super::*; |
| 2 | +추가: |
| 3 | +추가: fn finish_preview_catalog(model: &mut Model, allow: bool) -> usize { |
| 4 | +추가: let deadline = Instant::now() + Duration::from_secs(30); |
| 5 | +추가: let mut questions = 0; |
| 6 | +추가: while model.busy() { |
| 7 | +추가: model.poll(); |
| 8 | +추가: if let Some(question) = model.resource.clone() { |
| 9 | +추가: assert!(question.scope.entries); |
| 10 | +추가: assert!(!question.scope.ratio); |
| 11 | +추가: assert_eq!(question.action, ActionKind::Preview); |
| 12 | +추가: assert_eq!(model.estimated_usage().estimated_entries, Some(10_001)); |
| 13 | +추가: assert!(model.resource_reply(model.job_id().unwrap(), question.id, allow)); |
| 14 | +추가: questions += 1; |
| 15 | +추가: } |
| 16 | +추가: assert!(Instant::now() < deadline, "{:?}", model.error); |
| 17 | +추가: std::thread::sleep(Duration::from_millis(1)); |
| 18 | +추가: } |
| 19 | +추가: assert!(model.error.is_none(), "{:?}", model.error); |
| 20 | +추가: questions |
| 21 | +추가: } |
| 22 | +추가: |
| 23 | +추가: fn preview_catalog(count: usize, bytes: usize, allow: bool, image: bool) { |
| 24 | +추가: let name = if image { "small.png" } else { "small.txt" }; |
| 25 | +추가: let scratch = Scratch::new(); |
| 26 | +추가: let archive = scratch.path("many.zip"); |
| 27 | +추가: let generated = std::process::Command::new("python3") |
| 28 | +추가: .arg("-c") |
| 29 | +추가: .arg("import sys,zipfile; z=zipfile.ZipFile(sys.argv[1], 'w'); z.writestr(sys.argv[4], b'x'*int(sys.argv[3])); [z.writestr(f'{i}.bin', b'') for i in range(int(sys.argv[2])-1)]; z.close()") |
| 30 | +추가: .arg(&archive) |
| 31 | +추가: .arg(count.to_string()) |
| 32 | +추가: .arg(bytes.to_string()) |
| 33 | +추가: .arg(name) |
| 34 | +추가: .output() |
| 35 | +추가: .unwrap(); |
| 36 | +추가: assert!(generated.status.success()); |
| 37 | +추가: let mut factory = ProcessFactory::new(binary("zipelo-archive-worker")); |
| 38 | +추가: let mut model = Model::default(); |
| 39 | +추가: assert!(model.begin(Start::List { archive }, &mut factory)); |
| 40 | +추가: wait(&mut model); |
| 41 | +추가: if count > 10_000 { |
| 42 | +추가: assert_eq!( |
| 43 | +추가: model.terminal.as_ref().unwrap().error, |
| 44 | +추가: Some(ErrorCode::Limit) |
| 45 | +추가: ); |
| 46 | +추가: assert!(model.retry_expanded(&mut factory)); |
| 47 | +추가: let deadline = Instant::now() + Duration::from_secs(30); |
| 48 | +추가: while model.busy() { |
| 49 | +추가: model.poll(); |
| 50 | +추가: if let Some(question) = model.resource.clone() { |
| 51 | +추가: assert!(model.resource_reply(model.job_id().unwrap(), question.id, true)); |
| 52 | +추가: } |
| 53 | +추가: assert!(Instant::now() < deadline); |
| 54 | +추가: std::thread::sleep(Duration::from_millis(1)); |
| 55 | +추가: } |
| 56 | +추가: } |
| 57 | +추가: completed(&model); |
| 58 | +추가: assert_eq!(model.entries.len(), count); |
| 59 | +추가: let id = model |
| 60 | +추가: .entries |
| 61 | +추가: .iter() |
| 62 | +추가: .find(|entry| entry.name == name) |
| 63 | +추가: .unwrap() |
| 64 | +추가: .id; |
| 65 | +추가: model.selected.insert(id); |
| 66 | +추가: assert!(model.begin_preview(&mut factory)); |
| 67 | +추가: let questions = finish_preview_catalog(&mut model, allow); |
| 68 | +추가: assert_eq!(questions, usize::from(count > 10_000)); |
| 69 | +추가: if !allow { |
| 70 | +추가: assert!(model.preview.is_none()); |
| 71 | +추가: assert_ne!(model.terminal.as_ref().unwrap().outcome, Outcome::Completed); |
| 72 | +추가: } else if bytes > if image { 8 * 1024 * 1024 } else { 1024 * 1024 } { |
| 73 | +추가: assert_eq!( |
| 74 | +추가: model.terminal.as_ref().unwrap().error, |
| 75 | +추가: Some(ErrorCode::Limit) |
| 76 | +추가: ); |
| 77 | +추가: assert!(model.preview.is_none()); |
| 78 | +추가: assert!(!model.can_retry_expanded()); |
| 79 | +추가: } else { |
| 80 | +추가: completed(&model); |
| 81 | +추가: assert_eq!(model.preview.as_ref().unwrap().data, vec![b'x'; bytes]); |
| 82 | +추가: } |
| 83 | +추가: assert!(model.outputs.is_empty()); |
| 84 | +추가: assert_eq!(model.selected, [id].into_iter().collect()); |
| 85 | +추가: } |
| 86 | +추가: |
| 87 | +추가: #[test] |
| 88 | +추가: fn preview_catalog_at_default_entry_limit_needs_no_approval() { |
| 89 | +추가: preview_catalog(10_000, 7, true, false); |
| 90 | +추가: } |
| 91 | +추가: |
| 92 | +추가: #[test] |
| 93 | +추가: fn preview_catalog_over_default_entry_limit_requires_new_approval() { |
| 94 | +추가: preview_catalog(10_001, 7, true, false); |
| 95 | +추가: } |
| 96 | +추가: |
| 97 | +추가: #[test] |
| 98 | +추가: fn preview_catalog_approval_does_not_raise_text_size_limit() { |
| 99 | +추가: preview_catalog(10_001, 1024 * 1024 + 1, true, false); |
| 100 | +추가: } |
| 101 | +추가: |
| 102 | +추가: #[test] |
| 103 | +추가: fn preview_catalog_denial_does_not_show_data() { |
| 104 | +추가: preview_catalog(10_001, 7, false, false); |
| 105 | +추가: } |
| 106 | +추가: |
| 107 | +추가: #[test] |
| 108 | +추가: fn preview_catalog_approval_does_not_raise_image_size_limit() { |
| 109 | +추가: preview_catalog(10_001, 8 * 1024 * 1024 + 1, true, true); |
| 110 | +추가: } |