From 87da80d972c00358b46172ec9661e6a3a307a0a5 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Wed, 29 Mar 2023 22:34:18 +0200 Subject: Check that shared repos get the right config --- tests/cli.rs | 71 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 85f9708..a4b36a9 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,6 +1,7 @@ use anyhow::Result; use assert_cmd::{cargo::cargo_bin, Command}; use rexpect::session::{spawn_command, PtySession}; +use std::path::Path; use tempfile::TempDir; use user_info::{get_user_groups, get_username}; @@ -87,6 +88,31 @@ fn reports_error_with_nonsense_input() -> Result<()> { Ok(()) } +fn verify_repo_exists(repo_dir: &Path) { + Command::new("git") + .arg("rev-list") + .arg("--all") + .current_dir(repo_dir) + .assert() + .success() + .stdout(""); +} + +fn verify_repo_config_value(repo_dir: &Path, config_key: &str, config_value: Option<&str>) { + let assert = Command::new("git") + .args(["config", "--local", config_key]) + .current_dir(repo_dir) + .assert(); + match config_value { + Some(value) => { + assert.success().stdout(format!("{}\n", value)); + } + None => { + assert.failure().code(1); + } + } +} + #[test] fn can_init_a_new_git_repo() -> Result<()> { let mut c = spawn_interactive_process()?; @@ -99,19 +125,15 @@ fn can_init_a_new_git_repo() -> Result<()> { ))?; expect_prompt(&mut c.p)?; - Command::new("git") - .arg("rev-list") - .arg("--all") - .current_dir( - c.workdir - .as_ref() - .join("git") - .join(username) - .join(&format!("{}.git", repo_name)), - ) - .assert() - .success() - .stdout(""); + let repo_dir = c + .workdir + .as_ref() + .join("git") + .join(username) + .join(&format!("{}.git", repo_name)); + verify_repo_exists(&repo_dir); + verify_repo_config_value(&repo_dir, "core.sharedrepository", None); + Ok(()) } @@ -127,20 +149,15 @@ fn can_init_a_new_shared_git_repo() -> Result<()> { ))?; expect_prompt(&mut c.p)?; - Command::new("git") - .arg("rev-list") - .arg("--all") - .current_dir( - c.workdir - .as_ref() - .join("git") - .join(&group) - .join(&format!("{}.git", repo_name)), - ) - .assert() - .success() - .stdout(""); - // TODO: Check file permissions? Shared set in git config? + let repo_dir = c + .workdir + .as_ref() + .join("git") + .join(&group) + .join(&format!("{}.git", repo_name)); + verify_repo_exists(&repo_dir); + verify_repo_config_value(&repo_dir, "core.sharedrepository", Some("1")); + Ok(()) } -- cgit v1.2.3