summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-03-29 22:34:18 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-03-29 22:34:18 +0200
commit87da80d972c00358b46172ec9661e6a3a307a0a5 (patch)
tree95c6523ba72034f330e128b7eae873f03af94319 /tests
parent601c08b20bfb806d78fe92d9830960d1a333d5cf (diff)
Check that shared repos get the right config
Diffstat (limited to 'tests')
-rw-r--r--tests/cli.rs71
1 files changed, 44 insertions, 27 deletions
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(())
}