use std::path::PathBuf;
fn integration_enabled() -> bool {
std::env::var("GITWAY_INTEGRATION_TESTS")
.map(|v| !v.is_empty())
.unwrap_or(false)
}
fn gitway_binary() -> PathBuf {
let manifest = PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set by Cargo"),
);
manifest
.parent()
.expect("workspace root must exist")
.join("target/debug/gitway")
}
#[test]
fn git_clone_via_gitway_succeeds() {
if !integration_enabled() {
return;
}
let binary = gitway_binary();
assert!(
binary.exists(),
"gitway binary not found at {}; run `cargo build` first",
binary.display()
);
let tmp = tempfile::TempDir::new().expect("temp dir");
let dest = tmp.path().join("repo");
let status = std::process::Command::new("git")
.args([
"clone",
"--depth=1",
"git@github.com:steelbore/gitway.git",
dest.to_str().expect("UTF-8 path"),
])
.env("GIT_SSH_COMMAND", binary.to_str().expect("UTF-8 path"))
.env("GIT_TERMINAL_PROMPT", "0")
.status()
.expect("git must be installed");
assert!(
status.success(),
"git clone via gitway must exit with code 0, got: {status}"
);
assert!(
dest.join(".git").is_dir(),
".git directory must exist in the cloned repo"
);
}
#[test]
fn git_clone_without_key_exits_nonzero() {
if !integration_enabled() {
return;
}
let binary = gitway_binary();
assert!(
binary.exists(),
"gitway binary not found at {}; run `cargo build` first",
binary.display()
);
let tmp_home = tempfile::TempDir::new().expect("temp home dir");
let tmp_dest = tempfile::TempDir::new().expect("temp dest dir");
let status = std::process::Command::new("git")
.args([
"clone",
"--depth=1",
"git@github.com:steelbore/gitway.git",
tmp_dest.path().join("repo").to_str().expect("UTF-8 path"),
])
.env("GIT_SSH_COMMAND", binary.to_str().expect("UTF-8 path"))
.env("GIT_TERMINAL_PROMPT", "0")
.env("HOME", tmp_home.path())
.env_remove("SSH_AUTH_SOCK")
.status()
.expect("git must be installed");
assert!(
!status.success(),
"git clone without a key must exit non-zero"
);
}