diff options
Diffstat (limited to 'test_utils/src')
| -rw-r--r-- | test_utils/src/lib.rs | 204 | ||||
| -rw-r--r-- | test_utils/src/relay.rs | 8 |
2 files changed, 126 insertions, 86 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 1312610..7d79cff 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -544,10 +544,14 @@ impl CliTesterConfirmPrompt<'_> { | |||
| 544 | let mut s = String::new(); | 544 | let mut s = String::new(); |
| 545 | self.tester | 545 | self.tester |
| 546 | .formatter | 546 | .formatter |
| 547 | .format_confirm_prompt_selection(&mut s, self.prompt.as_str(), match input { | 547 | .format_confirm_prompt_selection( |
| 548 | None => self.default, | 548 | &mut s, |
| 549 | Some(_) => input, | 549 | self.prompt.as_str(), |
| 550 | }) | 550 | match input { |
| 551 | None => self.default, | ||
| 552 | Some(_) => input, | ||
| 553 | }, | ||
| 554 | ) | ||
| 551 | .expect("diagluer theme formatter should succeed"); | 555 | .expect("diagluer theme formatter should succeed"); |
| 552 | if !s.contains(self.prompt.as_str()) { | 556 | if !s.contains(self.prompt.as_str()) { |
| 553 | panic!("dialoguer must be broken as formatted prompt success doesnt contain prompt"); | 557 | panic!("dialoguer must be broken as formatted prompt success doesnt contain prompt"); |
| @@ -1017,10 +1021,13 @@ where | |||
| 1017 | cmd.env("RUST_BACKTRACE", "0"); | 1021 | cmd.env("RUST_BACKTRACE", "0"); |
| 1018 | cmd.args(args); | 1022 | cmd.args(args); |
| 1019 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1023 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1020 | rexpect::session::spawn_with_options(cmd, Options { | 1024 | rexpect::session::spawn_with_options( |
| 1021 | timeout_ms: Some(timeout_ms), | 1025 | cmd, |
| 1022 | strip_ansi_escape_codes: true, | 1026 | Options { |
| 1023 | }) | 1027 | timeout_ms: Some(timeout_ms), |
| 1028 | strip_ansi_escape_codes: true, | ||
| 1029 | }, | ||
| 1030 | ) | ||
| 1024 | } | 1031 | } |
| 1025 | 1032 | ||
| 1026 | pub fn rexpect_with_from_dir<I, S>( | 1033 | pub fn rexpect_with_from_dir<I, S>( |
| @@ -1038,10 +1045,13 @@ where | |||
| 1038 | cmd.current_dir(dir); | 1045 | cmd.current_dir(dir); |
| 1039 | cmd.args(args); | 1046 | cmd.args(args); |
| 1040 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1047 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1041 | rexpect::session::spawn_with_options(cmd, Options { | 1048 | rexpect::session::spawn_with_options( |
| 1042 | timeout_ms: Some(timeout_ms), | 1049 | cmd, |
| 1043 | strip_ansi_escape_codes: true, | 1050 | Options { |
| 1044 | }) | 1051 | timeout_ms: Some(timeout_ms), |
| 1052 | strip_ansi_escape_codes: true, | ||
| 1053 | }, | ||
| 1054 | ) | ||
| 1045 | } | 1055 | } |
| 1046 | 1056 | ||
| 1047 | pub fn remote_helper_rexpect_with_from_dir( | 1057 | pub fn remote_helper_rexpect_with_from_dir( |
| @@ -1056,10 +1066,13 @@ pub fn remote_helper_rexpect_with_from_dir( | |||
| 1056 | cmd.current_dir(dir); | 1066 | cmd.current_dir(dir); |
| 1057 | cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); | 1067 | cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); |
| 1058 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1068 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1059 | rexpect::session::spawn_with_options(cmd, Options { | 1069 | rexpect::session::spawn_with_options( |
| 1060 | timeout_ms: Some(timeout_ms), | 1070 | cmd, |
| 1061 | strip_ansi_escape_codes: true, | 1071 | Options { |
| 1062 | }) | 1072 | timeout_ms: Some(timeout_ms), |
| 1073 | strip_ansi_escape_codes: true, | ||
| 1074 | }, | ||
| 1075 | ) | ||
| 1063 | } | 1076 | } |
| 1064 | 1077 | ||
| 1065 | pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>( | 1078 | pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>( |
| @@ -1103,10 +1116,13 @@ where | |||
| 1103 | cmd.current_dir(dir); | 1116 | cmd.current_dir(dir); |
| 1104 | cmd.args(args); | 1117 | cmd.args(args); |
| 1105 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1118 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1106 | rexpect::session::spawn_with_options(cmd, Options { | 1119 | rexpect::session::spawn_with_options( |
| 1107 | timeout_ms: Some(timeout_ms), | 1120 | cmd, |
| 1108 | strip_ansi_escape_codes: true, | 1121 | Options { |
| 1109 | }) | 1122 | timeout_ms: Some(timeout_ms), |
| 1123 | strip_ansi_escape_codes: true, | ||
| 1124 | }, | ||
| 1125 | ) | ||
| 1110 | .context("spawning failed") | 1126 | .context("spawning failed") |
| 1111 | } | 1127 | } |
| 1112 | 1128 | ||
| @@ -1145,11 +1161,14 @@ pub fn get_proposal_branch_name( | |||
| 1145 | test_repo: &GitTestRepo, | 1161 | test_repo: &GitTestRepo, |
| 1146 | branch_name_in_event: &str, | 1162 | branch_name_in_event: &str, |
| 1147 | ) -> Result<String> { | 1163 | ) -> Result<String> { |
| 1148 | let events = block_on(get_events_from_cache(&test_repo.dir, vec![ | 1164 | let events = block_on(get_events_from_cache( |
| 1149 | nostr::Filter::default() | 1165 | &test_repo.dir, |
| 1150 | .kind(nostr_sdk::Kind::GitPatch) | 1166 | vec![ |
| 1151 | .hashtag("root"), | 1167 | nostr::Filter::default() |
| 1152 | ]))?; | 1168 | .kind(nostr_sdk::Kind::GitPatch) |
| 1169 | .hashtag("root"), | ||
| 1170 | ], | ||
| 1171 | ))?; | ||
| 1153 | get_proposal_branch_name_from_events(&events, branch_name_in_event) | 1172 | get_proposal_branch_name_from_events(&events, branch_name_in_event) |
| 1154 | } | 1173 | } |
| 1155 | 1174 | ||
| @@ -1303,45 +1322,54 @@ pub fn cli_tester_create_proposal( | |||
| 1303 | create_and_populate_branch(test_repo, branch_name, prefix, false, None)?; | 1322 | create_and_populate_branch(test_repo, branch_name, prefix, false, None)?; |
| 1304 | std::thread::sleep(std::time::Duration::from_millis(1000)); | 1323 | std::thread::sleep(std::time::Duration::from_millis(1000)); |
| 1305 | if let Some(in_reply_to) = in_reply_to { | 1324 | if let Some(in_reply_to) = in_reply_to { |
| 1306 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ | 1325 | let mut p = CliTester::new_from_dir( |
| 1307 | "--nsec", | 1326 | &test_repo.dir, |
| 1308 | TEST_KEY_1_NSEC, | 1327 | [ |
| 1309 | "--password", | 1328 | "--nsec", |
| 1310 | TEST_PASSWORD, | 1329 | TEST_KEY_1_NSEC, |
| 1311 | "--disable-cli-spinners", | 1330 | "--password", |
| 1312 | "send", | 1331 | TEST_PASSWORD, |
| 1313 | "HEAD~2", | 1332 | "--disable-cli-spinners", |
| 1314 | "--no-cover-letter", | 1333 | "send", |
| 1315 | "--in-reply-to", | 1334 | "HEAD~2", |
| 1316 | in_reply_to.as_str(), | 1335 | "--no-cover-letter", |
| 1317 | ]); | 1336 | "--in-reply-to", |
| 1337 | in_reply_to.as_str(), | ||
| 1338 | ], | ||
| 1339 | ); | ||
| 1318 | p.expect_end_eventually()?; | 1340 | p.expect_end_eventually()?; |
| 1319 | } else if let Some((title, description)) = cover_letter_title_and_description { | 1341 | } else if let Some((title, description)) = cover_letter_title_and_description { |
| 1320 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ | 1342 | let mut p = CliTester::new_from_dir( |
| 1321 | "--nsec", | 1343 | &test_repo.dir, |
| 1322 | TEST_KEY_1_NSEC, | 1344 | [ |
| 1323 | "--password", | 1345 | "--nsec", |
| 1324 | TEST_PASSWORD, | 1346 | TEST_KEY_1_NSEC, |
| 1325 | "--disable-cli-spinners", | 1347 | "--password", |
| 1326 | "send", | 1348 | TEST_PASSWORD, |
| 1327 | "HEAD~2", | 1349 | "--disable-cli-spinners", |
| 1328 | "--title", | 1350 | "send", |
| 1329 | format!("\"{title}\"").as_str(), | 1351 | "HEAD~2", |
| 1330 | "--description", | 1352 | "--title", |
| 1331 | format!("\"{description}\"").as_str(), | 1353 | format!("\"{title}\"").as_str(), |
| 1332 | ]); | 1354 | "--description", |
| 1355 | format!("\"{description}\"").as_str(), | ||
| 1356 | ], | ||
| 1357 | ); | ||
| 1333 | p.expect_end_eventually()?; | 1358 | p.expect_end_eventually()?; |
| 1334 | } else { | 1359 | } else { |
| 1335 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ | 1360 | let mut p = CliTester::new_from_dir( |
| 1336 | "--nsec", | 1361 | &test_repo.dir, |
| 1337 | TEST_KEY_1_NSEC, | 1362 | [ |
| 1338 | "--password", | 1363 | "--nsec", |
| 1339 | TEST_PASSWORD, | 1364 | TEST_KEY_1_NSEC, |
| 1340 | "--disable-cli-spinners", | 1365 | "--password", |
| 1341 | "send", | 1366 | TEST_PASSWORD, |
| 1342 | "HEAD~2", | 1367 | "--disable-cli-spinners", |
| 1343 | "--no-cover-letter", | 1368 | "send", |
| 1344 | ]); | 1369 | "HEAD~2", |
| 1370 | "--no-cover-letter", | ||
| 1371 | ], | ||
| 1372 | ); | ||
| 1345 | p.expect_end_eventually()?; | 1373 | p.expect_end_eventually()?; |
| 1346 | } | 1374 | } |
| 1347 | Ok(()) | 1375 | Ok(()) |
| @@ -1373,11 +1401,14 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( | |||
| 1373 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | 1401 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); |
| 1374 | p.expect("fetching updates...\r\n")?; | 1402 | p.expect("fetching updates...\r\n")?; |
| 1375 | p.expect_eventually("\r\n")?; // some updates listed here | 1403 | p.expect_eventually("\r\n")?; // some updates listed here |
| 1376 | let mut c = p.expect_choice("all proposals", vec![ | 1404 | let mut c = p.expect_choice( |
| 1377 | format!("\"{PROPOSAL_TITLE_3}\""), | 1405 | "all proposals", |
| 1378 | format!("\"{PROPOSAL_TITLE_2}\""), | 1406 | vec![ |
| 1379 | format!("\"{PROPOSAL_TITLE_1}\""), | 1407 | format!("\"{PROPOSAL_TITLE_3}\""), |
| 1380 | ])?; | 1408 | format!("\"{PROPOSAL_TITLE_2}\""), |
| 1409 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1410 | ], | ||
| 1411 | )?; | ||
| 1381 | c.succeeds_with( | 1412 | c.succeeds_with( |
| 1382 | if proposal_number == 3 { | 1413 | if proposal_number == 3 { |
| 1383 | 0 | 1414 | 0 |
| @@ -1389,12 +1420,15 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( | |||
| 1389 | true, | 1420 | true, |
| 1390 | None, | 1421 | None, |
| 1391 | )?; | 1422 | )?; |
| 1392 | let mut c = p.expect_choice("", vec![ | 1423 | let mut c = p.expect_choice( |
| 1393 | format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), | 1424 | "", |
| 1394 | format!("apply to current branch with `git am`"), | 1425 | vec![ |
| 1395 | format!("download to ./patches"), | 1426 | format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), |
| 1396 | format!("back"), | 1427 | format!("apply to current branch with `git am`"), |
| 1397 | ])?; | 1428 | format!("download to ./patches"), |
| 1429 | format!("back"), | ||
| 1430 | ], | ||
| 1431 | )?; | ||
| 1398 | c.succeeds_with(0, true, Some(0))?; | 1432 | c.succeeds_with(0, true, Some(0))?; |
| 1399 | p.expect_end_eventually()?; | 1433 | p.expect_end_eventually()?; |
| 1400 | Ok(()) | 1434 | Ok(()) |
| @@ -1466,9 +1500,10 @@ fn get_first_proposal_event_id() -> Result<nostr::EventId> { | |||
| 1466 | client.fetch_events( | 1500 | client.fetch_events( |
| 1467 | nostr::Filter::default() | 1501 | nostr::Filter::default() |
| 1468 | .kind(nostr::Kind::GitPatch) | 1502 | .kind(nostr::Kind::GitPatch) |
| 1469 | .custom_tags(nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), vec![ | 1503 | .custom_tags( |
| 1470 | "root", | 1504 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), |
| 1471 | ]), | 1505 | vec!["root"], |
| 1506 | ), | ||
| 1472 | Duration::from_millis(500), | 1507 | Duration::from_millis(500), |
| 1473 | ), | 1508 | ), |
| 1474 | )? | 1509 | )? |
| @@ -1496,15 +1531,18 @@ pub fn create_proposals_with_first_revised_and_repo_with_unrevised_proposal_chec | |||
| 1496 | 1531 | ||
| 1497 | amend_last_commit(&originating_repo, "add some ammended-commit.md")?; | 1532 | amend_last_commit(&originating_repo, "add some ammended-commit.md")?; |
| 1498 | 1533 | ||
| 1499 | let mut p = CliTester::new_from_dir(&originating_repo.dir, [ | 1534 | let mut p = CliTester::new_from_dir( |
| 1500 | "--nsec", | 1535 | &originating_repo.dir, |
| 1501 | TEST_KEY_1_NSEC, | 1536 | [ |
| 1502 | "--password", | 1537 | "--nsec", |
| 1503 | TEST_PASSWORD, | 1538 | TEST_KEY_1_NSEC, |
| 1504 | "--disable-cli-spinners", | 1539 | "--password", |
| 1505 | "push", | 1540 | TEST_PASSWORD, |
| 1506 | "--force", | 1541 | "--disable-cli-spinners", |
| 1507 | ]); | 1542 | "push", |
| 1543 | "--force", | ||
| 1544 | ], | ||
| 1545 | ); | ||
| 1508 | p.expect_end_eventually()?; | 1546 | p.expect_end_eventually()?; |
| 1509 | 1547 | ||
| 1510 | Ok((originating_repo, test_repo)) | 1548 | Ok((originating_repo, test_repo)) |
diff --git a/test_utils/src/relay.rs b/test_utils/src/relay.rs index 14778d9..b14f532 100644 --- a/test_utils/src/relay.rs +++ b/test_utils/src/relay.rs | |||
| @@ -161,9 +161,11 @@ impl<'a> Relay<'a> { | |||
| 161 | if let Some(listner) = self.req_listener { | 161 | if let Some(listner) = self.req_listener { |
| 162 | listner(self, client_id, subscription_id, vec![filter.clone()])?; | 162 | listner(self, client_id, subscription_id, vec![filter.clone()])?; |
| 163 | } else { | 163 | } else { |
| 164 | self.respond_standard_req(client_id, &subscription_id, &[ | 164 | self.respond_standard_req( |
| 165 | filter.clone() | 165 | client_id, |
| 166 | ])?; | 166 | &subscription_id, |
| 167 | &[filter.clone()], | ||
| 168 | )?; | ||
| 167 | // self.respond_eose(client_id, subscription_id)?; | 169 | // self.respond_eose(client_id, subscription_id)?; |
| 168 | } | 170 | } |
| 169 | // respond with events | 171 | // respond with events |