Skip to content

Commit

Permalink
Add test for repository cloning
Browse files Browse the repository at this point in the history
The mutation this resolves is removing the remove_dir_contents
implementation with a do-nothing impl.
  • Loading branch information
Notgnoshi committed Dec 30, 2024
1 parent e504530 commit 63d67b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions herostratus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions herostratus/src/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 63d67b9

Please sign in to comment.