diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-07-12 17:13:52 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-07-12 17:13:52 +0200 |
commit | 58664db6007920939d94977cc7382a5709b16558 (patch) | |
tree | ee4ecda12b31c47492e51777a81eaf4733fbdb6d /tests | |
parent | 84be3c9ae7a1b6a86f3a4ccc58e48eab46466b22 (diff) |
Starting with tests for the planned git housekeeping tasks
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cli.rs | 34 | ||||
-rw-r--r-- | tests/cli_test_utils/git.rs | 47 |
2 files changed, 80 insertions, 1 deletions
diff --git a/tests/cli.rs b/tests/cli.rs index b8ada66..0520e89 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -271,3 +271,37 @@ fn can_delete_a_repo() -> Result<()> { Ok(()) } + +#[test] +#[ignore] +fn git_housekeeping_repacks_objects() -> Result<()> { + let mut c = TestContext::new_interactive()?; + let repo_path = personal_repo_path(REPO_NAME); + let repo_dir = c.personal_repo_dir(REPO_NAME); + + c.p.send_line(&format!("init {}", REPO_NAME))?; + c.expect_successful_init_message(&repo_path)?; + + let checkout_dir = create_clone(&c, &repo_dir, REPO_NAME); + create_commit(&checkout_dir)?; + + // push to the repo + // check that objects exist, not packs + // run housekeeping + // check that only packs exist + Ok(()) +} + +#[test] +#[ignore] +fn git_housekeeping_cleans_out_stale_refs() -> Result<()> { + // create a repo + // create a local clone + // make branch b, with commit b + // push it to the repo + // delete branch b on the remote + // check that commit b is still accessible by hash on the remote + // run housekeeping + // check that commit b isn't in the repo anymore + Ok(()) +} diff --git a/tests/cli_test_utils/git.rs b/tests/cli_test_utils/git.rs index d3f35c4..150af45 100644 --- a/tests/cli_test_utils/git.rs +++ b/tests/cli_test_utils/git.rs @@ -1,5 +1,50 @@ +use crate::context::TestContext; +use anyhow::Result; use assert_cmd::Command; -use std::path::Path; +use std::{ + fs, + path::{Path, PathBuf}, +}; + +pub fn create_clone(c: &TestContext, repo_dir: &Path, relative_name: &str) -> PathBuf { + Command::new("git") + .arg("clone") + .arg(repo_dir) + .arg(relative_name) + .current_dir(&c.workdir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + c.workdir.as_ref().join(relative_name) +} + +pub fn create_commit(repo_dir: &Path) -> Result<String> { + let test_file_name = repo_dir.join("some_file"); + fs::write(test_file_name, "Some content or something")?; + Command::new("git") + .args(["add", "--all"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + Command::new("git") + .args(["commit", "-m", "A commit message"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .assert() + .success(); + + let commit_hash = String::from_utf8( + Command::new("git") + .args(["rev-parse", "HEAD"]) + .current_dir(&repo_dir) + .timeout(std::time::Duration::from_secs(3)) + .output()? + .stdout, + )?; + + Ok(commit_hash) +} pub fn verify_repo_exists(repo_dir: &Path) { Command::new("git") |