diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-23 13:57:23 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-23 13:57:23 +0000 |
| commit | d5284b758661c491e6a206570763f2982424b70a (patch) | |
| tree | cc7d8cee7b535999dc99e466a17127b1a94aee97 /tests/init.rs | |
| parent | a9e4c6772a378fd28edbca9b9267d2e7d08bee2c (diff) | |
feat(init): add customisation and defaults
- allow more cli input options
- allow customisation of more fields in interface
- change default identifer from shorthand root commit to short name
- defaults to existing repo event (users or other) or maintainers.yaml
Diffstat (limited to 'tests/init.rs')
| -rw-r--r-- | tests/init.rs | 260 |
1 files changed, 41 insertions, 219 deletions
diff --git a/tests/init.rs b/tests/init.rs index 1ad3810..d733643 100644 --- a/tests/init.rs +++ b/tests/init.rs | |||
| @@ -8,10 +8,40 @@ fn expect_msgs_first(p: &mut CliTester) -> Result<()> { | |||
| 8 | p.expect("logged in as fred\r\n")?; | 8 | p.expect("logged in as fred\r\n")?; |
| 9 | // // p.expect("searching for existing claims on repository...\r\n")?; | 9 | // // p.expect("searching for existing claims on repository...\r\n")?; |
| 10 | p.expect("maintainers.yaml created. commit and push.\r\n")?; | 10 | p.expect("maintainers.yaml created. commit and push.\r\n")?; |
| 11 | p.expect("this enables existing contributors to automatically fetch your repo event (instead of one from a pubkey pretending to be the maintainer) publishing repostory reference...\r\n")?; | ||
| 11 | p.expect("publishing repostory reference...\r\n")?; | 12 | p.expect("publishing repostory reference...\r\n")?; |
| 12 | Ok(()) | 13 | Ok(()) |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 16 | fn get_cli_args() -> Vec<&'static str> { | ||
| 17 | vec![ | ||
| 18 | "--nsec", | ||
| 19 | TEST_KEY_1_NSEC, | ||
| 20 | "--password", | ||
| 21 | TEST_PASSWORD, | ||
| 22 | "--disable-cli-spinners", | ||
| 23 | "init", | ||
| 24 | "--title", | ||
| 25 | "example-name", | ||
| 26 | "--identifier", | ||
| 27 | "example-identifier", | ||
| 28 | "--description", | ||
| 29 | "example-description", | ||
| 30 | "--web", | ||
| 31 | "https://exampleproject.xyz", | ||
| 32 | "https://gitworkshop.dev/123", | ||
| 33 | "--relays", | ||
| 34 | "ws://localhost:8055", | ||
| 35 | "ws://localhost:8056", | ||
| 36 | "--clone-url", | ||
| 37 | "https://git.myhosting.com/my-repo.git", | ||
| 38 | "--earliest-unique-commit", | ||
| 39 | "9ee507fc4357d7ee16a5d8901bedcd103f23c17d", | ||
| 40 | "--other-maintainers", | ||
| 41 | TEST_KEY_1_NPUB, | ||
| 42 | ] | ||
| 43 | } | ||
| 44 | |||
| 15 | mod when_repo_not_previously_claimed { | 45 | mod when_repo_not_previously_claimed { |
| 16 | use super::*; | 46 | use super::*; |
| 17 | 47 | ||
| @@ -29,27 +59,7 @@ mod when_repo_not_previously_claimed { | |||
| 29 | } | 59 | } |
| 30 | 60 | ||
| 31 | fn cli_tester_init(git_repo: &GitTestRepo) -> CliTester { | 61 | fn cli_tester_init(git_repo: &GitTestRepo) -> CliTester { |
| 32 | CliTester::new_from_dir( | 62 | CliTester::new_from_dir(&git_repo.dir, get_cli_args()) |
| 33 | &git_repo.dir, | ||
| 34 | [ | ||
| 35 | "--nsec", | ||
| 36 | TEST_KEY_1_NSEC, | ||
| 37 | "--password", | ||
| 38 | TEST_PASSWORD, | ||
| 39 | "--disable-cli-spinners", | ||
| 40 | "init", | ||
| 41 | "--title", | ||
| 42 | "example-name", | ||
| 43 | "--description", | ||
| 44 | "example-description", | ||
| 45 | "--web", | ||
| 46 | "https://exampleproject.xyz", | ||
| 47 | "https://gitworkshop.dev/123", | ||
| 48 | "--relays", | ||
| 49 | "ws://localhost:8055", | ||
| 50 | "ws://localhost:8056", | ||
| 51 | ], | ||
| 52 | ) | ||
| 53 | } | 63 | } |
| 54 | 64 | ||
| 55 | async fn prep_run_init() -> Result<( | 65 | async fn prep_run_init() -> Result<( |
| @@ -259,13 +269,12 @@ mod when_repo_not_previously_claimed { | |||
| 259 | } | 269 | } |
| 260 | } | 270 | } |
| 261 | 271 | ||
| 262 | mod tags { | 272 | mod tags_as_specified_in_args { |
| 263 | use super::*; | 273 | use super::*; |
| 264 | 274 | ||
| 265 | #[tokio::test] | 275 | #[tokio::test] |
| 266 | #[serial] | 276 | #[serial] |
| 267 | async fn d_replaceable_event_identifier_defaults_to_root_commit_id_shorthand() | 277 | async fn d_replaceable_event_identifier() -> Result<()> { |
| 268 | -> Result<()> { | ||
| 269 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; | 278 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; |
| 270 | for relay in [&r53, &r55, &r56, &r57] { | 279 | for relay in [&r53, &r55, &r56, &r57] { |
| 271 | let event: &nostr::Event = relay | 280 | let event: &nostr::Event = relay |
| @@ -275,10 +284,9 @@ mod when_repo_not_previously_claimed { | |||
| 275 | .unwrap(); | 284 | .unwrap(); |
| 276 | 285 | ||
| 277 | assert!( | 286 | assert!( |
| 278 | event | 287 | event.tags.iter().any( |
| 279 | .tags | 288 | |t| t.as_vec()[0].eq("d") && t.as_vec()[1].eq("example-identifier") |
| 280 | .iter() | 289 | ) |
| 281 | .any(|t| t.as_vec()[0].eq("d") && t.as_vec()[1].eq("9ee507f")) | ||
| 282 | ); | 290 | ); |
| 283 | } | 291 | } |
| 284 | Ok(()) | 292 | Ok(()) |
| @@ -286,7 +294,7 @@ mod when_repo_not_previously_claimed { | |||
| 286 | 294 | ||
| 287 | #[tokio::test] | 295 | #[tokio::test] |
| 288 | #[serial] | 296 | #[serial] |
| 289 | async fn root_commit_as_reference() -> Result<()> { | 297 | async fn earliest_unique_commit_as_reference() -> Result<()> { |
| 290 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; | 298 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; |
| 291 | for relay in [&r53, &r55, &r56, &r57] { | 299 | for relay in [&r53, &r55, &r56, &r57] { |
| 292 | let event: &nostr::Event = relay | 300 | let event: &nostr::Event = relay |
| @@ -352,7 +360,7 @@ mod when_repo_not_previously_claimed { | |||
| 352 | 360 | ||
| 353 | assert!( | 361 | assert!( |
| 354 | event.tags.iter().any(|t| t.as_vec()[0].eq("clone") | 362 | event.tags.iter().any(|t| t.as_vec()[0].eq("clone") |
| 355 | && t.as_vec()[1].eq("https://localhost:1000")) | 363 | && t.as_vec()[1].eq("https://git.myhosting.com/my-repo.git")) /* todo check it defaults to origin */ |
| 356 | ); | 364 | ); |
| 357 | } | 365 | } |
| 358 | Ok(()) | 366 | Ok(()) |
| @@ -404,7 +412,7 @@ mod when_repo_not_previously_claimed { | |||
| 404 | 412 | ||
| 405 | #[tokio::test] | 413 | #[tokio::test] |
| 406 | #[serial] | 414 | #[serial] |
| 407 | async fn current_user_in_maintainers() -> Result<()> { | 415 | async fn maintainers() -> Result<()> { |
| 408 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; | 416 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; |
| 409 | for relay in [&r53, &r55, &r56, &r57] { | 417 | for relay in [&r53, &r55, &r56, &r57] { |
| 410 | let event: &nostr::Event = relay | 418 | let event: &nostr::Event = relay |
| @@ -498,192 +506,6 @@ mod when_repo_not_previously_claimed { | |||
| 498 | } | 506 | } |
| 499 | } | 507 | } |
| 500 | } | 508 | } |
| 501 | 509 | // TODO: cli caputuring input | |
| 502 | mod when_repo_relays_not_specified { | ||
| 503 | use futures::join; | ||
| 504 | use test_utils::relay::Relay; | ||
| 505 | |||
| 506 | use super::*; | ||
| 507 | |||
| 508 | fn prep_git_repo() -> Result<GitTestRepo> { | ||
| 509 | let test_repo = GitTestRepo::default(); | ||
| 510 | test_repo.populate()?; | ||
| 511 | test_repo.add_remote("origin", "https://localhost:1000")?; | ||
| 512 | Ok(test_repo) | ||
| 513 | } | ||
| 514 | |||
| 515 | fn cli_tester_init(git_repo: &GitTestRepo) -> CliTester { | ||
| 516 | CliTester::new_from_dir( | ||
| 517 | &git_repo.dir, | ||
| 518 | [ | ||
| 519 | "--nsec", | ||
| 520 | TEST_KEY_1_NSEC, | ||
| 521 | "--password", | ||
| 522 | TEST_PASSWORD, | ||
| 523 | "--disable-cli-spinners", | ||
| 524 | "init", | ||
| 525 | "--title", | ||
| 526 | "example-name", | ||
| 527 | "--description", | ||
| 528 | "example-description", | ||
| 529 | "--web", | ||
| 530 | "https://exampleproject.xyz", | ||
| 531 | "https://gitworkshop.dev/123", | ||
| 532 | ], | ||
| 533 | ) | ||
| 534 | } | ||
| 535 | |||
| 536 | async fn prep_run_init() -> Result<( | ||
| 537 | Relay<'static>, | ||
| 538 | Relay<'static>, | ||
| 539 | Relay<'static>, | ||
| 540 | Relay<'static>, | ||
| 541 | Relay<'static>, | ||
| 542 | Relay<'static>, | ||
| 543 | )> { | ||
| 544 | let git_repo = prep_git_repo()?; | ||
| 545 | // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57) | ||
| 546 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 547 | Relay::new( | ||
| 548 | 8051, | ||
| 549 | None, | ||
| 550 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 551 | relay.respond_events( | ||
| 552 | client_id, | ||
| 553 | &subscription_id, | ||
| 554 | &vec![ | ||
| 555 | generate_test_key_1_metadata_event("fred"), | ||
| 556 | generate_test_key_1_relay_list_event(), | ||
| 557 | ], | ||
| 558 | )?; | ||
| 559 | Ok(()) | ||
| 560 | }), | ||
| 561 | ), | ||
| 562 | Relay::new(8052, None, None), | ||
| 563 | Relay::new(8053, None, None), | ||
| 564 | Relay::new(8055, None, None), | ||
| 565 | Relay::new(8056, None, None), | ||
| 566 | Relay::new(8057, None, None), | ||
| 567 | ); | ||
| 568 | |||
| 569 | // // check relay had the right number of events | ||
| 570 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 571 | let mut p = cli_tester_init(&git_repo); | ||
| 572 | p.expect_end_eventually()?; | ||
| 573 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 574 | relay::shutdown_relay(8000 + p)?; | ||
| 575 | } | ||
| 576 | Ok(()) | ||
| 577 | }); | ||
| 578 | |||
| 579 | // launch relay | ||
| 580 | let _ = join!( | ||
| 581 | r51.listen_until_close(), | ||
| 582 | r52.listen_until_close(), | ||
| 583 | r53.listen_until_close(), | ||
| 584 | r55.listen_until_close(), | ||
| 585 | r56.listen_until_close(), | ||
| 586 | r57.listen_until_close(), | ||
| 587 | ); | ||
| 588 | cli_tester_handle.join().unwrap()?; | ||
| 589 | Ok((r51, r52, r53, r55, r56, r57)) | ||
| 590 | } | ||
| 591 | |||
| 592 | mod tags { | ||
| 593 | use super::*; | ||
| 594 | |||
| 595 | #[tokio::test] | ||
| 596 | #[serial] | ||
| 597 | async fn relays_match_user_write_relays() -> Result<()> { | ||
| 598 | let (_, _, r53, r55, _, _) = prep_run_init().await?; | ||
| 599 | for relay in [&r53, &r55] { | ||
| 600 | let event: &nostr::Event = relay | ||
| 601 | .events | ||
| 602 | .iter() | ||
| 603 | .find(|e| e.kind.as_u64().eq(&REPOSITORY_KIND)) | ||
| 604 | .unwrap(); | ||
| 605 | |||
| 606 | assert!(event.tags.iter().any(|t| t.as_vec()[0].eq("relays") | ||
| 607 | && t.as_vec()[1].eq("ws://localhost:8053") | ||
| 608 | && t.as_vec()[2].eq("ws://localhost:8055"))); | ||
| 609 | } | ||
| 610 | Ok(()) | ||
| 611 | } | ||
| 612 | } | ||
| 613 | |||
| 614 | mod cli_ouput { | ||
| 615 | use super::*; | ||
| 616 | |||
| 617 | async fn run_test_async() -> Result<()> { | ||
| 618 | let git_repo = prep_git_repo()?; | ||
| 619 | |||
| 620 | // fallback (51,52) user write (53, 55) repo (55, 56) blaster (57) | ||
| 621 | let (mut r51, mut r52, mut r53, mut r55, mut r56, mut r57) = ( | ||
| 622 | Relay::new( | ||
| 623 | 8051, | ||
| 624 | None, | ||
| 625 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 626 | relay.respond_events( | ||
| 627 | client_id, | ||
| 628 | &subscription_id, | ||
| 629 | &vec![ | ||
| 630 | generate_test_key_1_metadata_event("fred"), | ||
| 631 | generate_test_key_1_relay_list_event(), | ||
| 632 | ], | ||
| 633 | )?; | ||
| 634 | Ok(()) | ||
| 635 | }), | ||
| 636 | ), | ||
| 637 | Relay::new(8052, None, None), | ||
| 638 | Relay::new(8053, None, None), | ||
| 639 | Relay::new(8055, None, None), | ||
| 640 | Relay::new(8056, None, None), | ||
| 641 | Relay::new(8057, None, None), | ||
| 642 | ); | ||
| 643 | |||
| 644 | // // check relay had the right number of events | ||
| 645 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 646 | let mut p = cli_tester_init(&git_repo); | ||
| 647 | expect_msgs_first(&mut p)?; | ||
| 648 | relay::expect_send_with_progress( | ||
| 649 | &mut p, | ||
| 650 | vec![ | ||
| 651 | (" [my-relay] [repo-relay] ws://localhost:8053", true, ""), | ||
| 652 | (" [my-relay] [repo-relay] ws://localhost:8055", true, ""), | ||
| 653 | (" [default] ws://localhost:8051", true, ""), | ||
| 654 | (" [default] ws://localhost:8052", true, ""), | ||
| 655 | (" [default] ws://localhost:8057", true, ""), | ||
| 656 | ], | ||
| 657 | 1, | ||
| 658 | )?; | ||
| 659 | p.expect_end_with_whitespace()?; | ||
| 660 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 661 | relay::shutdown_relay(8000 + p)?; | ||
| 662 | } | ||
| 663 | Ok(()) | ||
| 664 | }); | ||
| 665 | |||
| 666 | // launch relay | ||
| 667 | let _ = join!( | ||
| 668 | r51.listen_until_close(), | ||
| 669 | r52.listen_until_close(), | ||
| 670 | r53.listen_until_close(), | ||
| 671 | r55.listen_until_close(), | ||
| 672 | r56.listen_until_close(), | ||
| 673 | r57.listen_until_close(), | ||
| 674 | ); | ||
| 675 | cli_tester_handle.join().unwrap()?; | ||
| 676 | Ok(()) | ||
| 677 | } | ||
| 678 | |||
| 679 | #[tokio::test] | ||
| 680 | #[serial] | ||
| 681 | async fn check_cli_output() -> Result<()> { | ||
| 682 | run_test_async().await?; | ||
| 683 | Ok(()) | ||
| 684 | } | ||
| 685 | } | ||
| 686 | } | ||
| 687 | } | 510 | } |
| 688 | 511 | // TODO: when_updating_existing_repoistory correct defaults are used | |
| 689 | // TODO: when_updating_existing_repoistory | ||