diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-31 09:36:42 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-31 09:36:42 +0100 |
| commit | fea2e0a7c06acb2bd6223d24b80b2509c13e460d (patch) | |
| tree | 598d0ee3e07b8a2012bc8d7c67585b93c9149791 /test_utils/src/lib.rs | |
| parent | 0848d57c7654d09c3041022c231dfbbbfac17600 (diff) | |
test(remote): test helpers and basic fetch
create test helpers and setup basic test to verifiy
fetch was ran
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index bccfaf5..7697e6f 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -150,6 +150,10 @@ pub fn make_event_old_or_change_user( | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | pub fn generate_repo_ref_event() -> nostr::Event { | 152 | pub fn generate_repo_ref_event() -> nostr::Event { |
| 153 | generate_repo_ref_event_with_git_server("git:://123.gitexample.com/test".to_string()) | ||
| 154 | } | ||
| 155 | |||
| 156 | pub fn generate_repo_ref_event_with_git_server(git_server: String) -> nostr::Event { | ||
| 153 | // taken from test git_repo | 157 | // taken from test git_repo |
| 154 | // TODO - this may not be consistant across computers as it might take the | 158 | // TODO - this may not be consistant across computers as it might take the |
| 155 | // author and committer from global git config | 159 | // author and committer from global git config |
| @@ -167,7 +171,7 @@ pub fn generate_repo_ref_event() -> nostr::Event { | |||
| 167 | Tag::from_standardized(TagStandard::Description("example description".into())), | 171 | Tag::from_standardized(TagStandard::Description("example description".into())), |
| 168 | Tag::custom( | 172 | Tag::custom( |
| 169 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), | 173 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), |
| 170 | vec!["git:://123.gitexample.com/test".to_string()], | 174 | vec![git_server], |
| 171 | ), | 175 | ), |
| 172 | Tag::custom( | 176 | Tag::custom( |
| 173 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")), | 177 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")), |
| @@ -728,6 +732,14 @@ impl CliTester { | |||
| 728 | } | 732 | } |
| 729 | } | 733 | } |
| 730 | 734 | ||
| 735 | pub fn new_remote_helper_from_dir(dir: &PathBuf, nostr_remote_url: &str) -> Self { | ||
| 736 | Self { | ||
| 737 | rexpect_session: remote_helper_rexpect_with_from_dir(dir, nostr_remote_url, 3000) | ||
| 738 | .expect("rexpect to spawn new process"), | ||
| 739 | formatter: ColorfulTheme::default(), | ||
| 740 | } | ||
| 741 | } | ||
| 742 | |||
| 731 | pub fn restart_with<I, S>(&mut self, args: I) -> &mut Self | 743 | pub fn restart_with<I, S>(&mut self, args: I) -> &mut Self |
| 732 | where | 744 | where |
| 733 | I: IntoIterator<Item = S>, | 745 | I: IntoIterator<Item = S>, |
| @@ -943,6 +955,27 @@ where | |||
| 943 | ) | 955 | ) |
| 944 | } | 956 | } |
| 945 | 957 | ||
| 958 | pub fn remote_helper_rexpect_with_from_dir( | ||
| 959 | dir: &PathBuf, | ||
| 960 | nostr_remote_url: &str, | ||
| 961 | timeout_ms: u64, | ||
| 962 | ) -> Result<PtySession, rexpect::error::Error> { | ||
| 963 | let mut cmd = std::process::Command::new(assert_cmd::cargo::cargo_bin("git-remote-nostr")); | ||
| 964 | cmd.env("NGITTEST", "TRUE"); | ||
| 965 | cmd.env("GIT_DIR", dir); | ||
| 966 | cmd.env("RUST_BACKTRACE", "0"); | ||
| 967 | cmd.current_dir(dir); | ||
| 968 | cmd.args([dir.as_os_str().to_str().unwrap(), nostr_remote_url]); | ||
| 969 | // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes | ||
| 970 | rexpect::session::spawn_with_options( | ||
| 971 | cmd, | ||
| 972 | Options { | ||
| 973 | timeout_ms: Some(timeout_ms), | ||
| 974 | strip_ansi_escape_codes: true, | ||
| 975 | }, | ||
| 976 | ) | ||
| 977 | } | ||
| 978 | |||
| 946 | /** copied from client.rs */ | 979 | /** copied from client.rs */ |
| 947 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { | 980 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { |
| 948 | SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) | 981 | SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) |