upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-16 11:01:44 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-16 11:01:44 +0100
commit7704178c618f8ac455cd6b0582edb511a9e644c3 (patch)
tree775e425f0af2543eb12e4a4b1d4feb022611368f /test_utils
parent8cea674f58e806c22d2887cff5e6f76bc4dba0db (diff)
parentac53bca7e315848864ff9e51703720b5b466bc42 (diff)
Merge branch 'upgrade-dependancies'
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/Cargo.toml26
-rw-r--r--test_utils/src/lib.rs214
-rw-r--r--test_utils/src/relay.rs10
3 files changed, 145 insertions, 105 deletions
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml
index 2001733..8602416 100644
--- a/test_utils/Cargo.toml
+++ b/test_utils/Cargo.toml
@@ -4,21 +4,21 @@ version = "0.1.0"
4edition = "2021" 4edition = "2021"
5 5
6[dependencies] 6[dependencies]
7anyhow = "1.0.75" 7anyhow = "1.0.98"
8assert_cmd = "2.0.12" 8assert_cmd = "2.0.17"
9dialoguer = "0.11.0" 9dialoguer = "0.11.0"
10directories = "6.0.0" 10directories = "6.0.0"
11futures = "0.3.28" 11futures = "0.3.31"
12git2 = "0.20.2" 12git2 = "0.20.2"
13nostr = "0.41.0" 13nostr = "0.42.2"
14nostr-database = "0.41.0" 14nostr-database = "0.42.0"
15nostr-lmdb = "0.41.0" 15nostr-lmdb = "0.42.0"
16nostr-sdk = "0.41.0" 16nostr-sdk = "0.42.0"
17once_cell = "1.18.0" 17once_cell = "1.21.3"
18rand = "0.8" 18rand = "0.9"
19rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } 19rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" }
20simple-websockets = { git = "https://github.com/DanConwayDev/simple-websockets", branch= "auto-release-port" } 20simple-websockets = { git = "https://github.com/DanConwayDev/simple-websockets", branch= "auto-release-port" }
21strip-ansi-escapes = "0.2.0" 21strip-ansi-escapes = "0.2.1"
22tokio = { version = "1.40.0", features = ["full"] } 22tokio = { version = "1.46.1", features = ["full"] }
23tungstenite = "0.20.1" 23tungstenite = "0.27.0"
24sha2 = "0.10" \ No newline at end of file 24sha2 = "0.10"
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index 5feb64b..7d79cff 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -167,7 +167,7 @@ pub fn generate_repo_ref_event_with_git_server_with_keys(
167 .tags([ 167 .tags([
168 Tag::identifier( 168 Tag::identifier(
169 // root_commit.to_string() 169 // root_commit.to_string()
170 format!("{}-consider-it-random", root_commit), 170 format!("{root_commit}-consider-it-random"),
171 ), 171 ),
172 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())), 172 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())),
173 Tag::from_standardized(TagStandard::Name("example name".into())), 173 Tag::from_standardized(TagStandard::Name("example name".into())),
@@ -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
1026pub fn rexpect_with_from_dir<I, S>( 1033pub 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
1047pub fn remote_helper_rexpect_with_from_dir( 1057pub 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
1065pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>( 1078pub 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
@@ -1235,10 +1254,10 @@ pub fn create_and_populate_branch(
1235 test_repo.checkout("main")?; 1254 test_repo.checkout("main")?;
1236 test_repo.create_branch(branch_name)?; 1255 test_repo.create_branch(branch_name)?;
1237 test_repo.checkout(branch_name)?; 1256 test_repo.checkout(branch_name)?;
1238 let file_name = format!("{}3.md", prefix); 1257 let file_name = format!("{prefix}3.md");
1239 std::fs::write(test_repo.dir.join(&file_name), "some content")?; 1258 std::fs::write(test_repo.dir.join(&file_name), "some content")?;
1240 test_repo.stage_and_commit_custom_signature( 1259 test_repo.stage_and_commit_custom_signature(
1241 &format!("add {}3.md", prefix), 1260 &format!("add {prefix}3.md"),
1242 Some( 1261 Some(
1243 &Signature::new( 1262 &Signature::new(
1244 "Joe Bloggs", 1263 "Joe Bloggs",
@@ -1250,10 +1269,10 @@ pub fn create_and_populate_branch(
1250 commiter, 1269 commiter,
1251 )?; 1270 )?;
1252 if !only_one_commit { 1271 if !only_one_commit {
1253 let file_name = format!("{}4.md", prefix); 1272 let file_name = format!("{prefix}4.md");
1254 std::fs::write(test_repo.dir.join(&file_name), "some content")?; 1273 std::fs::write(test_repo.dir.join(&file_name), "some content")?;
1255 test_repo.stage_and_commit_custom_signature( 1274 test_repo.stage_and_commit_custom_signature(
1256 &format!("add {}4.md", prefix), 1275 &format!("add {prefix}4.md"),
1257 Some( 1276 Some(
1258 &Signature::new( 1277 &Signature::new(
1259 "Joe Bloggs", 1278 "Joe Bloggs",
@@ -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 e820651..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
@@ -186,7 +188,7 @@ impl<'a> Relay<'a> {
186 188
187pub fn shutdown_relay(port: u64) -> Result<()> { 189pub fn shutdown_relay(port: u64) -> Result<()> {
188 let mut counter = 0; 190 let mut counter = 0;
189 while let Ok((mut socket, _)) = tungstenite::connect(format!("ws://localhost:{}", port)) { 191 while let Ok((mut socket, _)) = tungstenite::connect(format!("ws://localhost:{port}")) {
190 counter += 1; 192 counter += 1;
191 if counter == 1 { 193 if counter == 1 {
192 socket.write(tungstenite::Message::text("shut me down"))?; 194 socket.write(tungstenite::Message::text("shut me down"))?;