-
Notifications
You must be signed in to change notification settings - Fork 0
test/2024-06-08-connect-remote-shims #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,57 @@ 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 "$@" | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
|
Comment on lines
+62
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's significant code duplication between |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// `git config` が失敗するシム | ||||||||||||||||||||||
| fn fake_git_fail_config(dir: &tempfile::TempDir) -> std::path::PathBuf { | ||||||||||||||||||||||
| let shim = dir.path().join("git"); | ||||||||||||||||||||||
|
|
@@ -217,6 +268,27 @@ fn connect_fails_on_git_config_error() { | |||||||||||||||||||||
| 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() | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
Comment on lines
+287
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Command::cargo_bin("gh-sync") | ||||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||||
| .current_dir(repo.path()) | ||||||||||||||||||||||
|
|
@@ -228,9 +300,9 @@ fn connect_fails_on_git_config_error() { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||
| fn connect_fails_on_git_config_error() { | ||||||||||||||||||||||
| fn connect_adds_remote_when_missing() { | ||||||||||||||||||||||
| let repo = setup_repo(); | ||||||||||||||||||||||
| let git_shim = fake_git_fail_config(&repo); | ||||||||||||||||||||||
| let git_shim = fake_git_remote_missing(&repo); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let path_env = format!( | ||||||||||||||||||||||
| "{}:{}", | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path to the
gitexecutable is hardcoded as/usr/bin/git. This can make the tests less portable ifgitis installed in a different location on other systems. Consider dynamically finding the path to thegitexecutable during test setup and injecting it into the shim script.