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
This commit is contained in:
Lee Bradley 2021-05-15 20:48:55 -05:00 committed by Stephan Dilly
parent 9117a1a5b7
commit fc5deec424

View file

@ -104,20 +104,16 @@ pub(crate) fn fetch(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::sync::tests::debug_cmd_print; use crate::sync::tests::{
use tempfile::TempDir; debug_cmd_print, repo_clone, repo_init,
};
#[test] #[test]
fn test_smoke() { fn test_smoke() {
let td = TempDir::new().unwrap(); let (remote_dir, _remote) = repo_init().unwrap();
let remote_path = remote_dir.path().to_str().unwrap();
debug_cmd_print( let (repo_dir, _repo) = repo_clone(remote_path).unwrap();
td.path().as_os_str().to_str().unwrap(), let repo_path = repo_dir.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 remotes = get_remotes(repo_path).unwrap(); let remotes = get_remotes(repo_path).unwrap();
@ -128,21 +124,16 @@ mod tests {
#[test] #[test]
fn test_default_remote() { 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( debug_cmd_print(
td.path().as_os_str().to_str().unwrap(), repo_path,
"git clone https://github.com/extrawurst/brewdump.git", &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(); let remotes = get_remotes(repo_path).unwrap();
assert_eq!( assert_eq!(
@ -159,26 +150,21 @@ mod tests {
#[test] #[test]
fn test_default_remote_out_of_order() { 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( debug_cmd_print(
td.path().as_os_str().to_str().unwrap(), repo_path,
"git clone https://github.com/extrawurst/brewdump.git", "git remote rename origin alternate",
); );
debug_cmd_print( debug_cmd_print(
td.path().as_os_str().to_str().unwrap(), repo_path,
"cd brewdump && git remote rename origin alternate", &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 //NOTE: aparently remotes are not chronolically sorted but alphabetically
let remotes = get_remotes(repo_path).unwrap(); let remotes = get_remotes(repo_path).unwrap();
@ -196,26 +182,21 @@ mod tests {
#[test] #[test]
fn test_default_remote_inconclusive() { 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( debug_cmd_print(
td.path().as_os_str().to_str().unwrap(), repo_path,
"git clone https://github.com/extrawurst/brewdump.git", "git remote rename origin alternate",
); );
debug_cmd_print( debug_cmd_print(
td.path().as_os_str().to_str().unwrap(), repo_path,
"cd brewdump && git remote rename origin alternate", &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(); let remotes = get_remotes(repo_path).unwrap();
assert_eq!( assert_eq!(
remotes, remotes,