From 64da82c661b2a28c7a258bd30c0084633d0e1896 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 11 Aug 2023 22:04:19 +0200 Subject: Create group directories if they don't already exist - With the correct ownership - With the correct permissions Fix #5 --- tests/cli.rs | 18 ++++++++++++++++++ tests/cli_test_utils/context.rs | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/cli.rs b/tests/cli.rs index 01c3347..34249c2 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -2,6 +2,7 @@ mod cli_test_utils; use anyhow::Result; use cli_test_utils::*; +use std::os::unix::fs::MetadataExt; const REPO_NAME: &str = "my-repository"; const REPO_NAME_2: &str = "my-other-repository"; @@ -83,6 +84,23 @@ fn can_init_a_new_shared_git_repo() -> Result<()> { verify_repo_exists(&repo_dir); verify_repo_config_value(&repo_dir, "core.sharedrepository", Some("1")); + let expected_gid = nix::unistd::Group::from_name(&group) + .unwrap() + .unwrap() + .gid + .as_raw(); + let group_dir = repo_dir.parent().unwrap(); + let group_dir_metadata = group_dir.metadata().unwrap(); + assert_eq!(group_dir_metadata.gid(), expected_gid); + assert_eq!( + group_dir_metadata.mode(), + 0o42770, + "Mode is {:o}", + group_dir_metadata.mode() + ); + + assert_eq!(repo_dir.metadata().unwrap().gid(), expected_gid); + Ok(()) } diff --git a/tests/cli_test_utils/context.rs b/tests/cli_test_utils/context.rs index 2517040..2c61085 100644 --- a/tests/cli_test_utils/context.rs +++ b/tests/cli_test_utils/context.rs @@ -100,15 +100,15 @@ impl TestContext { } } +pub fn arbitrary_user_group() -> String { + get_user_groups().into_iter().next().unwrap() +} + pub fn personal_repo_path(repo_name: &str) -> String { let username = get_username().unwrap(); format!("git/{username}/{repo_name}.git") } -pub fn arbitrary_user_group() -> String { - get_user_groups().into_iter().next().unwrap() -} - pub fn group_repo_path(group: &str, repo_name: &str) -> String { format!("git/{group}/{repo_name}.git") } -- cgit v1.2.3