diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/list.rs | 211 |
1 files changed, 209 insertions, 2 deletions
diff --git a/tests/list.rs b/tests/list.rs index 3f96da1..08c2e93 100644 --- a/tests/list.rs +++ b/tests/list.rs | |||
| @@ -1208,6 +1208,215 @@ mod when_main_branch_is_uptodate { | |||
| 1208 | } | 1208 | } |
| 1209 | } | 1209 | } |
| 1210 | 1210 | ||
| 1211 | mod when_latest_proposal_ammended_locally { | ||
| 1212 | // other rebase scenarios should work if this test passes | ||
| 1213 | use super::*; | ||
| 1214 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 1215 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 1216 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1217 | Relay::new(8051, None, None), | ||
| 1218 | Relay::new(8052, None, None), | ||
| 1219 | Relay::new(8053, None, None), | ||
| 1220 | Relay::new(8055, None, None), | ||
| 1221 | Relay::new(8056, None, None), | ||
| 1222 | ); | ||
| 1223 | |||
| 1224 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 1225 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1226 | r51.events.push(generate_repo_ref_event()); | ||
| 1227 | |||
| 1228 | r55.events.push(generate_repo_ref_event()); | ||
| 1229 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1230 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 1231 | |||
| 1232 | let cli_tester_handle = | ||
| 1233 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 1234 | let originating_repo = cli_tester_create_proposals()?; | ||
| 1235 | |||
| 1236 | let test_repo = GitTestRepo::default(); | ||
| 1237 | test_repo.populate()?; | ||
| 1238 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 1239 | |||
| 1240 | // simulating checking out the proposal (the commits_ids will match) | ||
| 1241 | create_and_populate_branch( | ||
| 1242 | &test_repo, | ||
| 1243 | "different-branch-name", | ||
| 1244 | "a", | ||
| 1245 | false, | ||
| 1246 | )?; | ||
| 1247 | // simulating ammending the proposal | ||
| 1248 | create_and_populate_branch( | ||
| 1249 | &test_repo, | ||
| 1250 | FEATURE_BRANCH_NAME_1, | ||
| 1251 | "a-changed", | ||
| 1252 | false, | ||
| 1253 | )?; | ||
| 1254 | |||
| 1255 | test_repo.checkout("main")?; | ||
| 1256 | p.expect("finding proposals...\r\n")?; | ||
| 1257 | let mut c = p.expect_choice( | ||
| 1258 | "all proposals", | ||
| 1259 | vec![ | ||
| 1260 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1261 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 1262 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 1263 | ], | ||
| 1264 | )?; | ||
| 1265 | c.succeeds_with(0, true, None)?; | ||
| 1266 | p.expect("finding commits...\r\n")?; | ||
| 1267 | p.expect_eventually("--force`\r\n")?; | ||
| 1268 | |||
| 1269 | let mut c = p.expect_choice( | ||
| 1270 | "", | ||
| 1271 | vec![ | ||
| 1272 | format!("checkout local branch with unpublished changes"), | ||
| 1273 | format!( | ||
| 1274 | "discard unpublished changes and checkout new revision" | ||
| 1275 | ), | ||
| 1276 | format!("apply to current branch with `git am`"), | ||
| 1277 | format!("download to ./patches"), | ||
| 1278 | "back".to_string(), | ||
| 1279 | ], | ||
| 1280 | )?; | ||
| 1281 | c.succeeds_with(1, false, Some(0))?; | ||
| 1282 | |||
| 1283 | p.expect_end_eventually_and_print()?; | ||
| 1284 | |||
| 1285 | for p in [51, 52, 53, 55, 56] { | ||
| 1286 | relay::shutdown_relay(8000 + p)?; | ||
| 1287 | } | ||
| 1288 | Ok((originating_repo, test_repo)) | ||
| 1289 | }); | ||
| 1290 | // launch relay | ||
| 1291 | let _ = join!( | ||
| 1292 | r51.listen_until_close(), | ||
| 1293 | r52.listen_until_close(), | ||
| 1294 | r53.listen_until_close(), | ||
| 1295 | r55.listen_until_close(), | ||
| 1296 | r56.listen_until_close(), | ||
| 1297 | ); | ||
| 1298 | let res = cli_tester_handle.join().unwrap()?; | ||
| 1299 | |||
| 1300 | Ok(res) | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | mod cli_prompts { | ||
| 1304 | use super::*; | ||
| 1305 | async fn run_async_prompts_to_choose_from_proposal_titles() -> Result<()> { | ||
| 1306 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 1307 | Relay::new(8051, None, None), | ||
| 1308 | Relay::new(8052, None, None), | ||
| 1309 | Relay::new(8053, None, None), | ||
| 1310 | Relay::new(8055, None, None), | ||
| 1311 | Relay::new(8056, None, None), | ||
| 1312 | ); | ||
| 1313 | |||
| 1314 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 1315 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1316 | r51.events.push(generate_repo_ref_event()); | ||
| 1317 | |||
| 1318 | r55.events.push(generate_repo_ref_event()); | ||
| 1319 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 1320 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 1321 | |||
| 1322 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 1323 | cli_tester_create_proposals()?; | ||
| 1324 | |||
| 1325 | let test_repo = GitTestRepo::default(); | ||
| 1326 | test_repo.populate()?; | ||
| 1327 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); | ||
| 1328 | |||
| 1329 | // simulating checking out the proposal (the commits_ids will match) | ||
| 1330 | create_and_populate_branch( | ||
| 1331 | &test_repo, | ||
| 1332 | "different-branch-name", | ||
| 1333 | "a", | ||
| 1334 | false, | ||
| 1335 | )?; | ||
| 1336 | // simulating ammending the proposal | ||
| 1337 | create_and_populate_branch( | ||
| 1338 | &test_repo, | ||
| 1339 | FEATURE_BRANCH_NAME_1, | ||
| 1340 | "a-changed", | ||
| 1341 | false, | ||
| 1342 | )?; | ||
| 1343 | |||
| 1344 | test_repo.checkout("main")?; | ||
| 1345 | p.expect("finding proposals...\r\n")?; | ||
| 1346 | let mut c = p.expect_choice( | ||
| 1347 | "all proposals", | ||
| 1348 | vec![ | ||
| 1349 | format!("\"{PROPOSAL_TITLE_1}\""), | ||
| 1350 | format!("\"{PROPOSAL_TITLE_2}\""), | ||
| 1351 | format!("\"{PROPOSAL_TITLE_3}\""), | ||
| 1352 | ], | ||
| 1353 | )?; | ||
| 1354 | c.succeeds_with(0, true, None)?; | ||
| 1355 | p.expect("finding commits...\r\n")?; | ||
| 1356 | p.expect("you have an ammended/rebase version the proposal that is unpublished\r\n")?; | ||
| 1357 | p.expect("you have previously applied the latest version of the proposal (2 ahead 0 behind 'main') but your local proposal branch has ammended or rebased it (2 ahead 0 behind 'main')\r\n")?; | ||
| 1358 | p.expect("to view the latest proposal but retain your changes:\r\n")?; | ||
| 1359 | p.expect(" 1) create a new branch off the tip commit of this one to store your changes\r\n")?; | ||
| 1360 | p.expect(" 2) run `ngit list` and checkout the latest published version of this proposal\r\n")?; | ||
| 1361 | p.expect("if you are confident in your changes consider running `ngit push --force`\r\n")?; | ||
| 1362 | |||
| 1363 | let mut c = p.expect_choice( | ||
| 1364 | "", | ||
| 1365 | vec![ | ||
| 1366 | format!("checkout local branch with unpublished changes"), | ||
| 1367 | format!( | ||
| 1368 | "discard unpublished changes and checkout new revision" | ||
| 1369 | ), | ||
| 1370 | format!("apply to current branch with `git am`"), | ||
| 1371 | format!("download to ./patches"), | ||
| 1372 | "back".to_string(), | ||
| 1373 | ], | ||
| 1374 | )?; | ||
| 1375 | c.succeeds_with(1, false, Some(1))?; | ||
| 1376 | p.expect_end_with("checked out latest version of proposal (2 ahead 0 behind 'main'), replacing unpublished version (2 ahead 0 behind 'main')\r\n")?; | ||
| 1377 | |||
| 1378 | for p in [51, 52, 53, 55, 56] { | ||
| 1379 | relay::shutdown_relay(8000 + p)?; | ||
| 1380 | } | ||
| 1381 | Ok(()) | ||
| 1382 | }); | ||
| 1383 | |||
| 1384 | // launch relay | ||
| 1385 | let _ = join!( | ||
| 1386 | r51.listen_until_close(), | ||
| 1387 | r52.listen_until_close(), | ||
| 1388 | r53.listen_until_close(), | ||
| 1389 | r55.listen_until_close(), | ||
| 1390 | r56.listen_until_close(), | ||
| 1391 | ); | ||
| 1392 | cli_tester_handle.join().unwrap()?; | ||
| 1393 | println!("{:?}", r55.events); | ||
| 1394 | Ok(()) | ||
| 1395 | } | ||
| 1396 | |||
| 1397 | #[tokio::test] | ||
| 1398 | #[serial] | ||
| 1399 | async fn out_reflects_second_choice_discarding_old_and_applying_new() | ||
| 1400 | -> Result<()> { | ||
| 1401 | let _ = run_async_prompts_to_choose_from_proposal_titles().await; | ||
| 1402 | Ok(()) | ||
| 1403 | } | ||
| 1404 | } | ||
| 1405 | |||
| 1406 | #[tokio::test] | ||
| 1407 | #[serial] | ||
| 1408 | async fn second_choice_discarded_unpublished_commits_and_checked_out_latest_revision() | ||
| 1409 | -> Result<()> { | ||
| 1410 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 1411 | println!("test_dir: {:?}", test_repo.dir); | ||
| 1412 | assert_eq!( | ||
| 1413 | test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 1414 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_1)?, | ||
| 1415 | ); | ||
| 1416 | Ok(()) | ||
| 1417 | } | ||
| 1418 | } | ||
| 1419 | |||
| 1211 | mod when_local_commits_on_uptodate_proposal { | 1420 | mod when_local_commits_on_uptodate_proposal { |
| 1212 | use super::*; | 1421 | use super::*; |
| 1213 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | 1422 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { |
| @@ -1627,8 +1836,6 @@ mod when_main_branch_is_uptodate { | |||
| 1627 | c.succeeds_with(0, true, None)?; | 1836 | c.succeeds_with(0, true, None)?; |
| 1628 | p.expect("finding commits...\r\n")?; | 1837 | p.expect("finding commits...\r\n")?; |
| 1629 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; | 1838 | p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; |
| 1630 | // its got here but tmpgit-32.. indicates that creatubg the eature | ||
| 1631 | // branch in line 1291 didnt work so the choices will be different | ||
| 1632 | let mut c = p.expect_choice( | 1839 | let mut c = p.expect_choice( |
| 1633 | "", | 1840 | "", |
| 1634 | vec![ | 1841 | vec![ |