Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 0 additions & 129 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,73 +58,6 @@ fi
shim
}

/// `git remote get-url` を失敗させて remote add を強制させるシム
fn fake_git_remote_missing(dir: &tempfile::TempDir) -> std::path::PathBuf {
let shim = dir.path().join("git");
fs::write(
&shim,
r#"#!/usr/bin/env sh
if [ "$1" = "config" ]; then
/usr/bin/git "$@"
elif [ "$1" = "remote" ] && [ "$2" = "get-url" ]; then
exit 1
else
echo git "$@"
exit 0
fi
"#,
)
.unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
fs::set_permissions(&shim, fs::Permissions::from_mode(0o755)).unwrap();
}
shim
}

/// `git remote get-url` を成功させつつ異なる URL を返し、set-url を誘発するシム
fn fake_git_remote_mismatch(dir: &tempfile::TempDir) -> std::path::PathBuf {
let shim = dir.path().join("git");
fs::write(
&shim,
r#"#!/usr/bin/env sh
if [ "$1" = "config" ]; then
/usr/bin/git "$@"
elif [ "$1" = "remote" ] && [ "$2" = "get-url" ]; then
echo https://example.com/other.git
exit 0
else
echo git "$@"
exit 0
fi
"#,
)
.unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
fs::set_permissions(&shim, fs::Permissions::from_mode(0o755)).unwrap();
}
shim
}

/// `git config` が失敗するシム
fn fake_git_fail_config(dir: &tempfile::TempDir) -> std::path::PathBuf {
let shim = dir.path().join("git");
fs::write(
&shim,
"#!/usr/bin/env sh\nif [ \"$1\" = \"config\" ]; then\n exit 1\nelse\n echo git \"$@\"\n exit 0\nfi\n",
)
.unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
fs::set_permissions(&shim, fs::Permissions::from_mode(0o755)).unwrap();
}
shim
}

#[test]
fn connect_and_list_roundtrip() {
let repo = setup_repo();
Expand Down Expand Up @@ -257,65 +190,3 @@ fn remove_mapping() {
.stdout(predicate::str::contains("No mappings"));
}

#[test]
fn connect_fails_on_git_config_error() {
let repo = setup_repo();
let git_shim = fake_git_fail_config(&repo);

let path_env = format!(
"{}:{}",
git_shim.parent().unwrap().display(),
std::env::var("PATH").unwrap()
);

Command::cargo_bin("gh-sync")
.unwrap()
.current_dir(repo.path())
.env("PATH", &path_env)
.args(&["connect", "web", "git@github.com:a/b.git"])
.assert()
.success()
.stdout(predicate::str::contains("git remote add"));
}

#[test]
fn connect_updates_remote_url() {
let repo = setup_repo();
let git_shim = fake_git_remote_mismatch(&repo);

let path_env = format!(
"{}:{}",
git_shim.parent().unwrap().display(),
std::env::var("PATH").unwrap()
);

Command::cargo_bin("gh-sync")
.unwrap()
.current_dir(repo.path())
.env("PATH", &path_env)
.args(&["connect", "web-app", "git@github.com:a/b.git"])
.assert()
.failure()
.stderr(predicate::str::contains("git config"));
}

#[test]
fn connect_adds_remote_when_missing() {
let repo = setup_repo();
let git_shim = fake_git_remote_missing(&repo);

let path_env = format!(
"{}:{}",
git_shim.parent().unwrap().display(),
std::env::var("PATH").unwrap()
);

Command::cargo_bin("gh-sync")
.unwrap()
.current_dir(repo.path())
.env("PATH", &path_env)
.args(&["connect", "web-app", "git@github.com:a/b.git"])
.assert()
.failure()
.stderr(predicate::str::contains("git config"));
}
Loading