From fc5deec42428ab9fd1d99157a55bed924fe73cfe Mon Sep 17 00:00:00 2001 From: Lee Bradley Date: Sat, 15 May 2021 20:48:55 -0500 Subject: [PATCH] Allow unit tests to be run offline Currently unit tests require a remote git repository from GitHub. This change allows unit tests to be run offline. Closes #613 --- asyncgit/src/sync/remotes/mod.rs | 77 ++++++++++++-------------------- 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/asyncgit/src/sync/remotes/mod.rs b/asyncgit/src/sync/remotes/mod.rs index c7cd68e4..20f55209 100644 --- a/asyncgit/src/sync/remotes/mod.rs +++ b/asyncgit/src/sync/remotes/mod.rs @@ -104,20 +104,16 @@ pub(crate) fn fetch( #[cfg(test)] mod tests { use super::*; - use crate::sync::tests::debug_cmd_print; - use tempfile::TempDir; + use crate::sync::tests::{ + debug_cmd_print, repo_clone, repo_init, + }; #[test] fn test_smoke() { - let td = TempDir::new().unwrap(); - - debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "git clone https://github.com/extrawurst/brewdump.git", - ); - - let repo_path = td.path().join("brewdump"); - let repo_path = repo_path.as_os_str().to_str().unwrap(); + let (remote_dir, _remote) = repo_init().unwrap(); + let remote_path = remote_dir.path().to_str().unwrap(); + let (repo_dir, _repo) = repo_clone(remote_path).unwrap(); + let repo_path = repo_dir.path().as_os_str().to_str().unwrap(); let remotes = get_remotes(repo_path).unwrap(); @@ -128,21 +124,16 @@ mod tests { #[test] fn test_default_remote() { - let td = TempDir::new().unwrap(); + let (remote_dir, _remote) = repo_init().unwrap(); + let remote_path = remote_dir.path().to_str().unwrap(); + let (repo_dir, _repo) = repo_clone(remote_path).unwrap(); + let repo_path = repo_dir.path().as_os_str().to_str().unwrap(); debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "git clone https://github.com/extrawurst/brewdump.git", + repo_path, + &format!("git remote add second {}", remote_path)[..], ); - debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "cd brewdump && git remote add second https://github.com/extrawurst/brewdump.git", - ); - - let repo_path = td.path().join("brewdump"); - let repo_path = repo_path.as_os_str().to_str().unwrap(); - let remotes = get_remotes(repo_path).unwrap(); assert_eq!( @@ -159,26 +150,21 @@ mod tests { #[test] fn test_default_remote_out_of_order() { - let td = TempDir::new().unwrap(); + let (remote_dir, _remote) = repo_init().unwrap(); + let remote_path = remote_dir.path().to_str().unwrap(); + let (repo_dir, _repo) = repo_clone(remote_path).unwrap(); + let repo_path = repo_dir.path().as_os_str().to_str().unwrap(); debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "git clone https://github.com/extrawurst/brewdump.git", + repo_path, + "git remote rename origin alternate", ); debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "cd brewdump && git remote rename origin alternate", + repo_path, + &format!("git remote add origin {}", remote_path)[..], ); - debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "cd brewdump && git remote add origin https://github.com/extrawurst/brewdump.git", - ); - - let repo_path = td.path().join("brewdump"); - let repo_path = repo_path.as_os_str().to_str().unwrap(); - //NOTE: aparently remotes are not chronolically sorted but alphabetically let remotes = get_remotes(repo_path).unwrap(); @@ -196,26 +182,21 @@ mod tests { #[test] fn test_default_remote_inconclusive() { - let td = TempDir::new().unwrap(); + let (remote_dir, _remote) = repo_init().unwrap(); + let remote_path = remote_dir.path().to_str().unwrap(); + let (repo_dir, _repo) = repo_clone(remote_path).unwrap(); + let repo_path = repo_dir.path().as_os_str().to_str().unwrap(); debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "git clone https://github.com/extrawurst/brewdump.git", + repo_path, + "git remote rename origin alternate", ); debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "cd brewdump && git remote rename origin alternate", + repo_path, + &format!("git remote add someremote {}", remote_path)[..], ); - debug_cmd_print( - td.path().as_os_str().to_str().unwrap(), - "cd brewdump && git remote add someremote https://github.com/extrawurst/brewdump.git", - ); - - let repo_path = td.path().join("brewdump"); - let repo_path = repo_path.as_os_str().to_str().unwrap(); - let remotes = get_remotes(repo_path).unwrap(); assert_eq!( remotes,