upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-22 12:58:12 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-22 12:58:12 +0000
commit70dd57966969f24fb81aabe412fb3667486f87b5 (patch)
treebe309b7252bb2d3e500b03e89656da08a88af390 /tests
parent312786fbdacd61fc9f3ed59612d9a6add9112b7f (diff)
test(list): local commits on uptodate proposal
add test for scenario and tweak copy
Diffstat (limited to 'tests')
-rw-r--r--tests/list.rs203
1 files changed, 197 insertions, 6 deletions
diff --git a/tests/list.rs b/tests/list.rs
index eb6dc3d..3f96da1 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -1208,14 +1208,205 @@ mod when_main_branch_is_uptodate {
1208 } 1208 }
1209 } 1209 }
1210 1210
1211 mod when_branch_is_ahead { 1211 mod when_local_commits_on_uptodate_proposal {
1212 // use super::*; 1212 use super::*;
1213 // TODO latest commit in proposal builds off an older commit in 1213 async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> {
1214 // proposal instead of previous. 1214 // fallback (51,52) user write (53, 55) repo (55, 56)
1215 // TODO current git user created commit on branch 1215 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
1216 Relay::new(8051, None, None),
1217 Relay::new(8052, None, None),
1218 Relay::new(8053, None, None),
1219 Relay::new(8055, None, None),
1220 Relay::new(8056, None, None),
1221 );
1222
1223 r51.events.push(generate_test_key_1_relay_list_event());
1224 r51.events.push(generate_test_key_1_metadata_event("fred"));
1225 r51.events.push(generate_repo_ref_event());
1226
1227 r55.events.push(generate_repo_ref_event());
1228 r55.events.push(generate_test_key_1_metadata_event("fred"));
1229 r55.events.push(generate_test_key_1_relay_list_event());
1230
1231 let cli_tester_handle = std::thread::spawn(
1232 move || -> Result<(GitTestRepo, GitTestRepo)> {
1233 let originating_repo = cli_tester_create_proposals()?;
1234
1235 let test_repo = GitTestRepo::default();
1236 test_repo.populate()?;
1237 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1238
1239 create_and_populate_branch(
1240 &test_repo,
1241 FEATURE_BRANCH_NAME_1,
1242 "a",
1243 false,
1244 )?;
1245 // add appended commit to local branch
1246 std::fs::write(test_repo.dir.join("appended.md"), "some content")?;
1247 test_repo.stage_and_commit("appended commit")?;
1248
1249 test_repo.checkout("main")?;
1250 p.expect("finding proposals...\r\n")?;
1251 let mut c = p.expect_choice(
1252 "all proposals",
1253 vec![
1254 format!("\"{PROPOSAL_TITLE_1}\""),
1255 format!("\"{PROPOSAL_TITLE_2}\""),
1256 format!("\"{PROPOSAL_TITLE_3}\""),
1257 ],
1258 )?;
1259 c.succeeds_with(0, true, None)?;
1260 p.expect("finding commits...\r\n")?;
1261 p.expect(
1262 "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n",
1263 )?;
1264
1265 let mut c = p.expect_choice(
1266 "",
1267 vec![
1268 format!("checkout proposal branch with 1 unpublished commits"),
1269 format!("back"),
1270 ],
1271 )?;
1272 c.succeeds_with(0, false, Some(0))?;
1273 p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?;
1274 p.expect_end()?;
1275
1276 for p in [51, 52, 53, 55, 56] {
1277 relay::shutdown_relay(8000 + p)?;
1278 }
1279 Ok((originating_repo, test_repo))
1280 },
1281 );
1282
1283 // launch relay
1284 let _ = join!(
1285 r51.listen_until_close(),
1286 r52.listen_until_close(),
1287 r53.listen_until_close(),
1288 r55.listen_until_close(),
1289 r56.listen_until_close(),
1290 );
1291 let res = cli_tester_handle.join().unwrap()?;
1292
1293 Ok(res)
1294 }
1295
1296 mod cli_prompts {
1297 use super::*;
1298 async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> {
1299 let (mut r51, mut r52, mut r53, mut r55, mut r56) = (
1300 Relay::new(8051, None, None),
1301 Relay::new(8052, None, None),
1302 Relay::new(8053, None, None),
1303 Relay::new(8055, None, None),
1304 Relay::new(8056, None, None),
1305 );
1306
1307 r51.events.push(generate_test_key_1_relay_list_event());
1308 r51.events.push(generate_test_key_1_metadata_event("fred"));
1309 r51.events.push(generate_repo_ref_event());
1310
1311 r55.events.push(generate_repo_ref_event());
1312 r55.events.push(generate_test_key_1_metadata_event("fred"));
1313 r55.events.push(generate_test_key_1_relay_list_event());
1314
1315 let cli_tester_handle = std::thread::spawn(move || -> Result<()> {
1316 cli_tester_create_proposals()?;
1317
1318 let test_repo = GitTestRepo::default();
1319 test_repo.populate()?;
1320 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
1321
1322 create_and_populate_branch(
1323 &test_repo,
1324 FEATURE_BRANCH_NAME_1,
1325 "a",
1326 false,
1327 )?;
1328 // add appended commit to local branch
1329 std::fs::write(test_repo.dir.join("appended.md"), "some content")?;
1330 test_repo.stage_and_commit("appended commit")?;
1331
1332 test_repo.checkout("main")?;
1333 p.expect("finding proposals...\r\n")?;
1334 let mut c = p.expect_choice(
1335 "all proposals",
1336 vec![
1337 format!("\"{PROPOSAL_TITLE_1}\""),
1338 format!("\"{PROPOSAL_TITLE_2}\""),
1339 format!("\"{PROPOSAL_TITLE_3}\""),
1340 ],
1341 )?;
1342 c.succeeds_with(0, true, None)?;
1343 p.expect("finding commits...\r\n")?;
1344 p.expect(
1345 "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n",
1346 )?;
1347
1348 let mut c = p.expect_choice(
1349 "",
1350 vec![
1351 format!("checkout proposal branch with 1 unpublished commits"),
1352 format!("back"),
1353 ],
1354 )?;
1355 c.succeeds_with(0, false, Some(0))?;
1356 p.expect("checked out proposal branch with 1 unpublished commits (3 ahead 0 behind 'main')\r\n")?;
1357 p.expect_end()?;
1358
1359 for p in [51, 52, 53, 55, 56] {
1360 relay::shutdown_relay(8000 + p)?;
1361 }
1362 Ok(())
1363 });
1364
1365 // launch relay
1366 let _ = join!(
1367 r51.listen_until_close(),
1368 r52.listen_until_close(),
1369 r53.listen_until_close(),
1370 r55.listen_until_close(),
1371 r56.listen_until_close(),
1372 );
1373 cli_tester_handle.join().unwrap()?;
1374 println!("{:?}", r55.events);
1375 Ok(())
1376 }
1377
1378 #[tokio::test]
1379 #[serial]
1380 async fn prompts_to_choose_from_proposal_titles() -> Result<()> {
1381 let _ = run_async_prompts_to_choose_from_proposal_titles().await;
1382 Ok(())
1383 }
1384 }
1385
1386 #[tokio::test]
1387 #[serial]
1388 async fn proposal_branch_checked_out() -> Result<()> {
1389 let (_, test_repo) = prep_and_run().await?;
1390 assert_eq!(
1391 FEATURE_BRANCH_NAME_1,
1392 test_repo.get_checked_out_branch_name()?,
1393 );
1394 Ok(())
1395 }
1396
1397 #[tokio::test]
1398 #[serial]
1399 async fn didnt_overwrite_local_appendments() -> Result<()> {
1400 let (originating_repo, test_repo) = prep_and_run().await?;
1401 assert_ne!(
1402 test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1403 originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?,
1404 );
1405 Ok(())
1406 }
1216 } 1407 }
1217 1408
1218 mod when_latest_event_rebases_branch { 1409 mod when_latest_revision_rebases_branch {
1219 use std::time::Duration; 1410 use std::time::Duration;
1220 1411
1221 use super::*; 1412 use super::*;