diff options
Diffstat (limited to 'tests/ngit_send.rs')
| -rw-r--r-- | tests/ngit_send.rs | 148 |
1 files changed, 145 insertions, 3 deletions
diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs index 2ae858a..7946aef 100644 --- a/tests/ngit_send.rs +++ b/tests/ngit_send.rs | |||
| @@ -75,7 +75,7 @@ mod when_commits_behind_ask_to_proceed { | |||
| 75 | let mut r51 = create_relay_51()?; | 75 | let mut r51 = create_relay_51()?; |
| 76 | // // check relay had the right number of events | 76 | // // check relay had the right number of events |
| 77 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 77 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 78 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 78 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["-i", "send", "HEAD~2"]); |
| 79 | expect_confirm_prompt(&mut p)?; | 79 | expect_confirm_prompt(&mut p)?; |
| 80 | p.exit()?; | 80 | p.exit()?; |
| 81 | relay::shutdown_relay(8051)?; | 81 | relay::shutdown_relay(8051)?; |
| @@ -94,7 +94,7 @@ mod when_commits_behind_ask_to_proceed { | |||
| 94 | let test_repo = prep_test_repo()?; | 94 | let test_repo = prep_test_repo()?; |
| 95 | let mut r51 = create_relay_51()?; | 95 | let mut r51 = create_relay_51()?; |
| 96 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 96 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 97 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 97 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["-i", "send", "HEAD~2"]); |
| 98 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(false))?; | 98 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(false))?; |
| 99 | p.expect_end_with("Error: aborting so commits can be rebased\r\n")?; | 99 | p.expect_end_with("Error: aborting so commits can be rebased\r\n")?; |
| 100 | relay::shutdown_relay(8051)?; | 100 | relay::shutdown_relay(8051)?; |
| @@ -113,7 +113,7 @@ mod when_commits_behind_ask_to_proceed { | |||
| 113 | let test_repo = prep_test_repo()?; | 113 | let test_repo = prep_test_repo()?; |
| 114 | let mut r51 = create_relay_51()?; | 114 | let mut r51 = create_relay_51()?; |
| 115 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 115 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 116 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | 116 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["-i", "send", "HEAD~2"]); |
| 117 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(true))?; | 117 | expect_confirm_prompt(&mut p)?.succeeds_with(Some(true))?; |
| 118 | p.expect("? include cover letter")?; | 118 | p.expect("? include cover letter")?; |
| 119 | p.exit()?; | 119 | p.exit()?; |
| @@ -1235,6 +1235,7 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main { | |||
| 1235 | 1235 | ||
| 1236 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { | 1236 | fn cli_tester_create_proposal(git_repo: &GitTestRepo) -> CliTester { |
| 1237 | let args = vec![ | 1237 | let args = vec![ |
| 1238 | "-i", | ||
| 1238 | "--nsec", | 1239 | "--nsec", |
| 1239 | TEST_KEY_1_NSEC, | 1240 | TEST_KEY_1_NSEC, |
| 1240 | "--password", | 1241 | "--password", |
| @@ -1943,3 +1944,144 @@ mod in_reply_to_mentions_npub_and_nprofile_which_get_mentioned_in_proposal_root | |||
| 1943 | Ok(()) | 1944 | Ok(()) |
| 1944 | } | 1945 | } |
| 1945 | } | 1946 | } |
| 1947 | |||
| 1948 | mod non_interactive_validation { | ||
| 1949 | use super::*; | ||
| 1950 | |||
| 1951 | #[test] | ||
| 1952 | fn bare_send_errors_with_helpful_message() -> Result<()> { | ||
| 1953 | let test_repo = prep_git_repo()?; | ||
| 1954 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send"]); | ||
| 1955 | let output = p.expect_end_eventually()?; | ||
| 1956 | assert!(output.contains("ngit send requires additional arguments")); | ||
| 1957 | assert!(output.contains("<SINCE_OR_RANGE>")); | ||
| 1958 | assert!(output.contains("--title")); | ||
| 1959 | assert!(output.contains("--description")); | ||
| 1960 | assert!(output.contains("--defaults")); | ||
| 1961 | assert!(output.contains("--interactive")); | ||
| 1962 | Ok(()) | ||
| 1963 | } | ||
| 1964 | |||
| 1965 | #[test] | ||
| 1966 | fn send_with_range_only_errors() -> Result<()> { | ||
| 1967 | let test_repo = prep_git_repo()?; | ||
| 1968 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "HEAD~2"]); | ||
| 1969 | let output = p.expect_end_eventually()?; | ||
| 1970 | assert!(output.contains("ngit send requires additional arguments")); | ||
| 1971 | assert!(output.contains("--title")); | ||
| 1972 | assert!(output.contains("--description")); | ||
| 1973 | assert!(output.contains("--defaults")); | ||
| 1974 | Ok(()) | ||
| 1975 | } | ||
| 1976 | |||
| 1977 | #[test] | ||
| 1978 | fn send_force_pr_without_title_errors() -> Result<()> { | ||
| 1979 | let test_repo = prep_git_repo()?; | ||
| 1980 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "--force-pr", "HEAD~2"]); | ||
| 1981 | let output = p.expect_end_eventually()?; | ||
| 1982 | assert!(output.contains("ngit send requires additional arguments")); | ||
| 1983 | assert!(output.contains("--title")); | ||
| 1984 | assert!(output.contains("--description")); | ||
| 1985 | assert!(output.contains("--defaults")); | ||
| 1986 | Ok(()) | ||
| 1987 | } | ||
| 1988 | |||
| 1989 | #[test] | ||
| 1990 | fn send_description_without_title_errors() -> Result<()> { | ||
| 1991 | let test_repo = prep_git_repo()?; | ||
| 1992 | let mut p = | ||
| 1993 | CliTester::new_from_dir(&test_repo.dir, ["send", "--description", "Y", "HEAD~2"]); | ||
| 1994 | let output = p.expect_end_eventually()?; | ||
| 1995 | assert!(output.contains("ngit send requires --title when --description is provided")); | ||
| 1996 | assert!(output.contains("--title")); | ||
| 1997 | Ok(()) | ||
| 1998 | } | ||
| 1999 | |||
| 2000 | #[test] | ||
| 2001 | fn send_title_without_description_errors() -> Result<()> { | ||
| 2002 | let test_repo = prep_git_repo()?; | ||
| 2003 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["send", "--title", "X", "HEAD~2"]); | ||
| 2004 | let output = p.expect_end_eventually()?; | ||
| 2005 | assert!(output.contains("ngit send requires --description when --title is provided")); | ||
| 2006 | assert!(output.contains("--description")); | ||
| 2007 | Ok(()) | ||
| 2008 | } | ||
| 2009 | |||
| 2010 | #[tokio::test] | ||
| 2011 | #[serial] | ||
| 2012 | async fn send_defaults_sends_patches_without_cover_letter() -> Result<()> { | ||
| 2013 | let git_repo = prep_git_repo()?; | ||
| 2014 | |||
| 2015 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 2016 | Relay::new( | ||
| 2017 | 8051, | ||
| 2018 | None, | ||
| 2019 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 2020 | relay.respond_events( | ||
| 2021 | client_id, | ||
| 2022 | &subscription_id, | ||
| 2023 | &vec![ | ||
| 2024 | generate_test_key_1_metadata_event("fred"), | ||
| 2025 | generate_test_key_1_relay_list_event(), | ||
| 2026 | ], | ||
| 2027 | )?; | ||
| 2028 | Ok(()) | ||
| 2029 | }), | ||
| 2030 | ), | ||
| 2031 | Relay::new(8052, None, None), | ||
| 2032 | Relay::new(8053, None, None), | ||
| 2033 | Relay::new( | ||
| 2034 | 8055, | ||
| 2035 | None, | ||
| 2036 | Some(&|relay, client_id, subscription_id, _| -> Result<()> { | ||
| 2037 | relay.respond_events( | ||
| 2038 | client_id, | ||
| 2039 | &subscription_id, | ||
| 2040 | &vec![generate_repo_ref_event()], | ||
| 2041 | )?; | ||
| 2042 | Ok(()) | ||
| 2043 | }), | ||
| 2044 | ), | ||
| 2045 | Relay::new(8056, None, None), | ||
| 2046 | ); | ||
| 2047 | |||
| 2048 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 2049 | let mut p = CliTester::new_from_dir( | ||
| 2050 | &git_repo.dir, | ||
| 2051 | [ | ||
| 2052 | "--nsec", | ||
| 2053 | TEST_KEY_1_NSEC, | ||
| 2054 | "--password", | ||
| 2055 | TEST_PASSWORD, | ||
| 2056 | "--disable-cli-spinners", | ||
| 2057 | "--defaults", | ||
| 2058 | "send", | ||
| 2059 | ], | ||
| 2060 | ); | ||
| 2061 | p.expect_end_eventually()?; | ||
| 2062 | for p in [51, 52, 53, 55, 56] { | ||
| 2063 | relay::shutdown_relay(8000 + p)?; | ||
| 2064 | } | ||
| 2065 | Ok(()) | ||
| 2066 | }); | ||
| 2067 | |||
| 2068 | let _ = join!( | ||
| 2069 | r51.listen_until_close(), | ||
| 2070 | r52.listen_until_close(), | ||
| 2071 | r53.listen_until_close(), | ||
| 2072 | r55.listen_until_close(), | ||
| 2073 | r56.listen_until_close(), | ||
| 2074 | ); | ||
| 2075 | cli_tester_handle.join().unwrap()?; | ||
| 2076 | |||
| 2077 | // verify patches sent without cover letter | ||
| 2078 | for relay in [&r53, &r55, &r56] { | ||
| 2079 | assert_eq!( | ||
| 2080 | relay.events.iter().filter(|e| is_cover_letter(e)).count(), | ||
| 2081 | 0, | ||
| 2082 | ); | ||
| 2083 | assert_eq!(relay.events.iter().filter(|e| is_patch(e)).count(), 2); | ||
| 2084 | } | ||
| 2085 | Ok(()) | ||
| 2086 | } | ||
| 2087 | } | ||