diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-16 09:00:46 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-16 09:46:30 +0000 |
| commit | 4ee83e2fe5335a8afd78439c35f029c4a472e797 (patch) | |
| tree | bdb111b191e7a68cb74ce29b4bb2757b4b7be91f /test_utils | |
| parent | 5fe839e2bf8ceb2931c1984efb2d956980431203 (diff) | |
chore: bump nix flake rust nightly `fmt` overlay
update the rust nightly `fmt` overlay which needs to be pinned
to a specific version (this case by date)
update formatting in main files via `cargo fmt`
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/lib.rs | 203 | ||||
| -rw-r--r-- | test_utils/src/relay.rs | 2 |
2 files changed, 84 insertions, 121 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 5079c26..5c8d7a5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -6,15 +6,15 @@ use std::{ | |||
| 6 | time::Duration, | 6 | time::Duration, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{bail, ensure, Context, Result}; | 9 | use anyhow::{Context, Result, bail, ensure}; |
| 10 | use dialoguer::theme::{ColorfulTheme, Theme}; | 10 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 11 | use futures::executor::block_on; | 11 | use futures::executor::block_on; |
| 12 | use git::GitTestRepo; | 12 | use git::GitTestRepo; |
| 13 | use git2::{Signature, Time}; | 13 | use git2::{Signature, Time}; |
| 14 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 14 | use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; |
| 15 | use nostr_database::NostrEventsDatabase; | 15 | use nostr_database::NostrEventsDatabase; |
| 16 | use nostr_lmdb::NostrLMDB; | 16 | use nostr_lmdb::NostrLMDB; |
| 17 | use nostr_sdk::{serde_json, Client, NostrSigner, TagStandard}; | 17 | use nostr_sdk::{Client, NostrSigner, TagStandard, serde_json}; |
| 18 | use once_cell::sync::Lazy; | 18 | use once_cell::sync::Lazy; |
| 19 | use rexpect::session::{Options, PtySession}; | 19 | use rexpect::session::{Options, PtySession}; |
| 20 | use strip_ansi_escapes::strip_str; | 20 | use strip_ansi_escapes::strip_str; |
| @@ -530,14 +530,10 @@ impl CliTesterConfirmPrompt<'_> { | |||
| 530 | let mut s = String::new(); | 530 | let mut s = String::new(); |
| 531 | self.tester | 531 | self.tester |
| 532 | .formatter | 532 | .formatter |
| 533 | .format_confirm_prompt_selection( | 533 | .format_confirm_prompt_selection(&mut s, self.prompt.as_str(), match input { |
| 534 | &mut s, | 534 | None => self.default, |
| 535 | self.prompt.as_str(), | 535 | Some(_) => input, |
| 536 | match input { | 536 | }) |
| 537 | None => self.default, | ||
| 538 | Some(_) => input, | ||
| 539 | }, | ||
| 540 | ) | ||
| 541 | .expect("diagluer theme formatter should succeed"); | 537 | .expect("diagluer theme formatter should succeed"); |
| 542 | if !s.contains(self.prompt.as_str()) { | 538 | if !s.contains(self.prompt.as_str()) { |
| 543 | panic!("dialoguer must be broken as formatted prompt success doesnt contain prompt"); | 539 | panic!("dialoguer must be broken as formatted prompt success doesnt contain prompt"); |
| @@ -1007,13 +1003,10 @@ where | |||
| 1007 | cmd.env("RUST_BACKTRACE", "0"); | 1003 | cmd.env("RUST_BACKTRACE", "0"); |
| 1008 | cmd.args(args); | 1004 | cmd.args(args); |
| 1009 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1005 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1010 | rexpect::session::spawn_with_options( | 1006 | rexpect::session::spawn_with_options(cmd, Options { |
| 1011 | cmd, | 1007 | timeout_ms: Some(timeout_ms), |
| 1012 | Options { | 1008 | strip_ansi_escape_codes: true, |
| 1013 | timeout_ms: Some(timeout_ms), | 1009 | }) |
| 1014 | strip_ansi_escape_codes: true, | ||
| 1015 | }, | ||
| 1016 | ) | ||
| 1017 | } | 1010 | } |
| 1018 | 1011 | ||
| 1019 | pub fn rexpect_with_from_dir<I, S>( | 1012 | pub fn rexpect_with_from_dir<I, S>( |
| @@ -1031,13 +1024,10 @@ where | |||
| 1031 | cmd.current_dir(dir); | 1024 | cmd.current_dir(dir); |
| 1032 | cmd.args(args); | 1025 | cmd.args(args); |
| 1033 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1026 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1034 | rexpect::session::spawn_with_options( | 1027 | rexpect::session::spawn_with_options(cmd, Options { |
| 1035 | cmd, | 1028 | timeout_ms: Some(timeout_ms), |
| 1036 | Options { | 1029 | strip_ansi_escape_codes: true, |
| 1037 | timeout_ms: Some(timeout_ms), | 1030 | }) |
| 1038 | strip_ansi_escape_codes: true, | ||
| 1039 | }, | ||
| 1040 | ) | ||
| 1041 | } | 1031 | } |
| 1042 | 1032 | ||
| 1043 | pub fn remote_helper_rexpect_with_from_dir( | 1033 | pub fn remote_helper_rexpect_with_from_dir( |
| @@ -1052,13 +1042,10 @@ pub fn remote_helper_rexpect_with_from_dir( | |||
| 1052 | cmd.current_dir(dir); | 1042 | cmd.current_dir(dir); |
| 1053 | cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); | 1043 | cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); |
| 1054 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1044 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1055 | rexpect::session::spawn_with_options( | 1045 | rexpect::session::spawn_with_options(cmd, Options { |
| 1056 | cmd, | 1046 | timeout_ms: Some(timeout_ms), |
| 1057 | Options { | 1047 | strip_ansi_escape_codes: true, |
| 1058 | timeout_ms: Some(timeout_ms), | 1048 | }) |
| 1059 | strip_ansi_escape_codes: true, | ||
| 1060 | }, | ||
| 1061 | ) | ||
| 1062 | } | 1049 | } |
| 1063 | 1050 | ||
| 1064 | pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>( | 1051 | pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>( |
| @@ -1102,13 +1089,10 @@ where | |||
| 1102 | cmd.current_dir(dir); | 1089 | cmd.current_dir(dir); |
| 1103 | cmd.args(args); | 1090 | cmd.args(args); |
| 1104 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | 1091 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes |
| 1105 | rexpect::session::spawn_with_options( | 1092 | rexpect::session::spawn_with_options(cmd, Options { |
| 1106 | cmd, | 1093 | timeout_ms: Some(timeout_ms), |
| 1107 | Options { | 1094 | strip_ansi_escape_codes: true, |
| 1108 | timeout_ms: Some(timeout_ms), | 1095 | }) |
| 1109 | strip_ansi_escape_codes: true, | ||
| 1110 | }, | ||
| 1111 | ) | ||
| 1112 | .context("spawning failed") | 1096 | .context("spawning failed") |
| 1113 | } | 1097 | } |
| 1114 | 1098 | ||
| @@ -1137,14 +1121,11 @@ pub fn get_proposal_branch_name( | |||
| 1137 | test_repo: &GitTestRepo, | 1121 | test_repo: &GitTestRepo, |
| 1138 | branch_name_in_event: &str, | 1122 | branch_name_in_event: &str, |
| 1139 | ) -> Result<String> { | 1123 | ) -> Result<String> { |
| 1140 | let events = block_on(get_events_from_cache( | 1124 | let events = block_on(get_events_from_cache(&test_repo.dir, vec![ |
| 1141 | &test_repo.dir, | 1125 | nostr::Filter::default() |
| 1142 | vec![ | 1126 | .kind(nostr_sdk::Kind::GitPatch) |
| 1143 | nostr::Filter::default() | 1127 | .hashtag("root"), |
| 1144 | .kind(nostr_sdk::Kind::GitPatch) | 1128 | ]))?; |
| 1145 | .hashtag("root"), | ||
| 1146 | ], | ||
| 1147 | ))?; | ||
| 1148 | get_proposal_branch_name_from_events(&events, branch_name_in_event) | 1129 | get_proposal_branch_name_from_events(&events, branch_name_in_event) |
| 1149 | } | 1130 | } |
| 1150 | 1131 | ||
| @@ -1296,54 +1277,45 @@ pub fn cli_tester_create_proposal( | |||
| 1296 | create_and_populate_branch(test_repo, branch_name, prefix, false, None)?; | 1277 | create_and_populate_branch(test_repo, branch_name, prefix, false, None)?; |
| 1297 | std::thread::sleep(std::time::Duration::from_millis(1000)); | 1278 | std::thread::sleep(std::time::Duration::from_millis(1000)); |
| 1298 | if let Some(in_reply_to) = in_reply_to { | 1279 | if let Some(in_reply_to) = in_reply_to { |
| 1299 | let mut p = CliTester::new_from_dir( | 1280 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ |
| 1300 | &test_repo.dir, | 1281 | "--nsec", |
| 1301 | [ | 1282 | TEST_KEY_1_NSEC, |
| 1302 | "--nsec", | 1283 | "--password", |
| 1303 | TEST_KEY_1_NSEC, | 1284 | TEST_PASSWORD, |
| 1304 | "--password", | 1285 | "--disable-cli-spinners", |
| 1305 | TEST_PASSWORD, | 1286 | "send", |
| 1306 | "--disable-cli-spinners", | 1287 | "HEAD~2", |
| 1307 | "send", | 1288 | "--no-cover-letter", |
| 1308 | "HEAD~2", | 1289 | "--in-reply-to", |
| 1309 | "--no-cover-letter", | 1290 | in_reply_to.as_str(), |
| 1310 | "--in-reply-to", | 1291 | ]); |
| 1311 | in_reply_to.as_str(), | ||
| 1312 | ], | ||
| 1313 | ); | ||
| 1314 | p.expect_end_eventually()?; | 1292 | p.expect_end_eventually()?; |
| 1315 | } else if let Some((title, description)) = cover_letter_title_and_description { | 1293 | } else if let Some((title, description)) = cover_letter_title_and_description { |
| 1316 | let mut p = CliTester::new_from_dir( | 1294 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ |
| 1317 | &test_repo.dir, | 1295 | "--nsec", |
| 1318 | [ | 1296 | TEST_KEY_1_NSEC, |
| 1319 | "--nsec", | 1297 | "--password", |
| 1320 | TEST_KEY_1_NSEC, | 1298 | TEST_PASSWORD, |
| 1321 | "--password", | 1299 | "--disable-cli-spinners", |
| 1322 | TEST_PASSWORD, | 1300 | "send", |
| 1323 | "--disable-cli-spinners", | 1301 | "HEAD~2", |
| 1324 | "send", | 1302 | "--title", |
| 1325 | "HEAD~2", | 1303 | format!("\"{title}\"").as_str(), |
| 1326 | "--title", | 1304 | "--description", |
| 1327 | format!("\"{title}\"").as_str(), | 1305 | format!("\"{description}\"").as_str(), |
| 1328 | "--description", | 1306 | ]); |
| 1329 | format!("\"{description}\"").as_str(), | ||
| 1330 | ], | ||
| 1331 | ); | ||
| 1332 | p.expect_end_eventually()?; | 1307 | p.expect_end_eventually()?; |
| 1333 | } else { | 1308 | } else { |
| 1334 | let mut p = CliTester::new_from_dir( | 1309 | let mut p = CliTester::new_from_dir(&test_repo.dir, [ |
| 1335 | &test_repo.dir, | 1310 | "--nsec", |
| 1336 | [ | 1311 | TEST_KEY_1_NSEC, |
| 1337 | "--nsec", | 1312 | "--password", |
| 1338 | TEST_KEY_1_NSEC, | 1313 | TEST_PASSWORD, |
| 1339 | "--password", | 1314 | "--disable-cli-spinners", |
| 1340 | TEST_PASSWORD, | 1315 | "send", |
| 1341 | "--disable-cli-spinners", | 1316 | "HEAD~2", |
| 1342 | "send", | 1317 | "--no-cover-letter", |
| 1343 | "HEAD~2", | 1318 | ]); |
| 1344 | "--no-cover-letter", | ||
| 1345 | ], | ||
| 1346 | ); | ||
| 1347 | p.expect_end_eventually()?; | 1319 | p.expect_end_eventually()?; |
| 1348 | } | 1320 | } |
| 1349 | Ok(()) | 1321 | Ok(()) |
| @@ -1375,14 +1347,11 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( | |||
| 1375 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | 1347 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); |
| 1376 | p.expect("fetching updates...\r\n")?; | 1348 | p.expect("fetching updates...\r\n")?; |
| 1377 | p.expect_eventually("\r\n")?; // some updates listed here | 1349 | p.expect_eventually("\r\n")?; // some updates listed here |
| 1378 | let mut c = p.expect_choice( | 1350 | let mut c = p.expect_choice("all proposals", vec![ |
| 1379 | "all proposals", | 1351 | format!("\"{PROPOSAL_TITLE_3}\""), |
| 1380 | vec![ | 1352 | format!("\"{PROPOSAL_TITLE_2}\""), |
| 1381 | format!("\"{PROPOSAL_TITLE_3}\""), | 1353 | format!("\"{PROPOSAL_TITLE_1}\""), |
| 1382 | format!("\"{PROPOSAL_TITLE_2}\""), | 1354 | ])?; |
| 1383 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1384 | ], | ||
| 1385 | )?; | ||
| 1386 | c.succeeds_with( | 1355 | c.succeeds_with( |
| 1387 | if proposal_number == 3 { | 1356 | if proposal_number == 3 { |
| 1388 | 0 | 1357 | 0 |
| @@ -1394,15 +1363,12 @@ pub fn use_ngit_list_to_download_and_checkout_proposal_branch( | |||
| 1394 | true, | 1363 | true, |
| 1395 | None, | 1364 | None, |
| 1396 | )?; | 1365 | )?; |
| 1397 | let mut c = p.expect_choice( | 1366 | let mut c = p.expect_choice("", vec![ |
| 1398 | "", | 1367 | format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), |
| 1399 | vec![ | 1368 | format!("apply to current branch with `git am`"), |
| 1400 | format!("create and checkout proposal branch (2 ahead 0 behind 'main')"), | 1369 | format!("download to ./patches"), |
| 1401 | format!("apply to current branch with `git am`"), | 1370 | format!("back"), |
| 1402 | format!("download to ./patches"), | 1371 | ])?; |
| 1403 | format!("back"), | ||
| 1404 | ], | ||
| 1405 | )?; | ||
| 1406 | c.succeeds_with(0, true, Some(0))?; | 1372 | c.succeeds_with(0, true, Some(0))?; |
| 1407 | p.expect_end_eventually()?; | 1373 | p.expect_end_eventually()?; |
| 1408 | Ok(()) | 1374 | Ok(()) |
| @@ -1505,18 +1471,15 @@ pub fn create_proposals_with_first_revised_and_repo_with_unrevised_proposal_chec | |||
| 1505 | 1471 | ||
| 1506 | amend_last_commit(&originating_repo, "add some ammended-commit.md")?; | 1472 | amend_last_commit(&originating_repo, "add some ammended-commit.md")?; |
| 1507 | 1473 | ||
| 1508 | let mut p = CliTester::new_from_dir( | 1474 | let mut p = CliTester::new_from_dir(&originating_repo.dir, [ |
| 1509 | &originating_repo.dir, | 1475 | "--nsec", |
| 1510 | [ | 1476 | TEST_KEY_1_NSEC, |
| 1511 | "--nsec", | 1477 | "--password", |
| 1512 | TEST_KEY_1_NSEC, | 1478 | TEST_PASSWORD, |
| 1513 | "--password", | 1479 | "--disable-cli-spinners", |
| 1514 | TEST_PASSWORD, | 1480 | "push", |
| 1515 | "--disable-cli-spinners", | 1481 | "--force", |
| 1516 | "push", | 1482 | ]); |
| 1517 | "--force", | ||
| 1518 | ], | ||
| 1519 | ); | ||
| 1520 | p.expect_end_eventually()?; | 1483 | p.expect_end_eventually()?; |
| 1521 | 1484 | ||
| 1522 | Ok((originating_repo, test_repo)) | 1485 | Ok((originating_repo, test_repo)) |
diff --git a/test_utils/src/relay.rs b/test_utils/src/relay.rs index d767a5a..634b2d6 100644 --- a/test_utils/src/relay.rs +++ b/test_utils/src/relay.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use std::collections::HashMap; | 1 | use std::collections::HashMap; |
| 2 | 2 | ||
| 3 | use anyhow::{bail, Result}; | 3 | use anyhow::{Result, bail}; |
| 4 | use nostr::{ClientMessage, JsonUtil, RelayMessage}; | 4 | use nostr::{ClientMessage, JsonUtil, RelayMessage}; |
| 5 | 5 | ||
| 6 | use crate::CliTester; | 6 | use crate::CliTester; |