From 63d67b9bd3ff019b675ad0ee1ac9a89a9c866b33 Mon Sep 17 00:00:00 2001 From: Austin Gill Date: Sun, 29 Dec 2024 21:12:14 -0600 Subject: [PATCH] Add test for repository cloning The mutation this resolves is removing the remove_dir_contents implementation with a do-nothing impl. --- Cargo.lock | 1 + herostratus/Cargo.toml | 1 + herostratus/src/git/clone.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 157a855..8c58223 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1408,6 +1408,7 @@ dependencies = [ "inventory", "predicates", "serde", + "tempfile", "toml", "tracing", "tracing-subscriber", diff --git a/herostratus/Cargo.toml b/herostratus/Cargo.toml index 8711b7b..c58ec15 100644 --- a/herostratus/Cargo.toml +++ b/herostratus/Cargo.toml @@ -19,6 +19,7 @@ git2.workspace = true gix.workspace = true inventory.workspace = true serde.workspace = true +tempfile.workspace = true toml.workspace = true tracing.workspace = true tracing-subscriber.workspace = true diff --git a/herostratus/src/git/clone.rs b/herostratus/src/git/clone.rs index e347992..983624b 100644 --- a/herostratus/src/git/clone.rs +++ b/herostratus/src/git/clone.rs @@ -478,4 +478,32 @@ mod tests { // branch assert_eq!(fetched_commits, 5); } + + #[test] + fn test_force_clone() { + let upstream = fixtures::repository::simplest().unwrap(); + let tempdir = tempfile::tempdir().unwrap(); + let downstream_dir = tempdir.path().join("downstream"); + std::fs::create_dir_all(&downstream_dir).unwrap(); + // Something's already using the clone directory + let sentinel = downstream_dir.join("sentinel.txt"); + std::fs::File::create(&sentinel).unwrap(); + assert!(sentinel.exists()); + + let config = crate::config::RepositoryConfig { + branch: None, // HEAD + url: format!("file://{}", upstream.tempdir.path().display()), + path: downstream_dir, + ..Default::default() + }; + let force = false; + let result = clone_repository(&config, force); + assert!(result.is_err()); + assert!(sentinel.exists()); + + let force = true; + let result = clone_repository(&config, force); + assert!(result.is_ok()); + assert!(!sentinel.exists()); + } }