upleb.uk

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

summaryrefslogtreecommitdiff
path: root/test_utils/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-08-08 13:01:21 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-08-08 13:02:24 +0100
commit8deb88804743c295f756d405afc58313fa3601fd (patch)
tree784e98667e883ba656b0c56e8c06f40bd3f20060 /test_utils/src
parent44cee8791ce9175db4b39c7d21d8ade022b5024e (diff)
test(remote): helper to run as git remote helper
add a test helper function to enable the git remote helper to be run as intended (via git) rather than calling it directly
Diffstat (limited to 'test_utils/src')
-rw-r--r--test_utils/src/lib.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index ff3833d..3270a79 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -740,6 +740,18 @@ impl CliTester {
740 } 740 }
741 } 741 }
742 742
743 pub fn new_git_with_remote_helper_from_dir<I, S>(dir: &PathBuf, args: I) -> Self
744 where
745 I: IntoIterator<Item = S>,
746 S: AsRef<OsStr>,
747 {
748 Self {
749 rexpect_session: git_with_remote_helper_rexpect_with_from_dir(dir, args, 3000)
750 .expect("rexpect to spawn new process"),
751 formatter: ColorfulTheme::default(),
752 }
753 }
754
743 pub fn restart_with<I, S>(&mut self, args: I) -> &mut Self 755 pub fn restart_with<I, S>(&mut self, args: I) -> &mut Self
744 where 756 where
745 I: IntoIterator<Item = S>, 757 I: IntoIterator<Item = S>,
@@ -987,6 +999,55 @@ pub fn remote_helper_rexpect_with_from_dir(
987 ) 999 )
988} 1000}
989 1001
1002pub fn git_with_remote_helper_rexpect_with_from_dir<I, S>(
1003 dir: &PathBuf,
1004 args: I,
1005 timeout_ms: u64,
1006) -> Result<PtySession>
1007where
1008 I: IntoIterator<Item = S>,
1009 S: AsRef<std::ffi::OsStr>,
1010{
1011 let git_exec_dir = dir.parent().unwrap().join("tmpgit-git-exec-path");
1012 if !git_exec_dir.exists() {
1013 std::fs::create_dir_all(&git_exec_dir)?;
1014 let src = PathBuf::from(
1015 String::from_utf8_lossy(
1016 &std::process::Command::new("git")
1017 .arg("--exec-path")
1018 .output()?
1019 .stdout,
1020 )
1021 .trim()
1022 .to_string(),
1023 );
1024 for entry in std::fs::read_dir(src)? {
1025 let src_path = entry?.path();
1026 std::fs::copy(&src_path, &git_exec_dir.join(src_path.file_name().unwrap()))?;
1027 }
1028 }
1029 std::fs::copy(
1030 assert_cmd::cargo::cargo_bin("git-remote-nostr"),
1031 git_exec_dir.join("git-remote-nostr"),
1032 )?;
1033
1034 let mut cmd = std::process::Command::new("git");
1035 cmd.env("GIT_EXEC_PATH", git_exec_dir);
1036 cmd.env("NGITTEST", "TRUE");
1037 cmd.env("RUST_BACKTRACE", "0");
1038 cmd.current_dir(dir);
1039 cmd.args(args);
1040 // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes
1041 rexpect::session::spawn_with_options(
1042 cmd,
1043 Options {
1044 timeout_ms: Some(timeout_ms),
1045 strip_ansi_escape_codes: true,
1046 },
1047 )
1048 .context("spawning failed")
1049}
1050
990/** copied from client.rs */ 1051/** copied from client.rs */
991async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { 1052async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> {
992 SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) 1053 SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite"))