mirror of
https://github.com/chenasraf/git-open.git
synced 2026-05-18 01:38:59 +00:00
test: add/fix remote tests
This commit is contained in:
@@ -16,3 +16,4 @@ Commands:
|
||||
|
||||
Flags:
|
||||
-s, --silent Silent mode (no output)
|
||||
-r, --remote <name> Use a specific remote (default: origin)
|
||||
|
||||
@@ -10,7 +10,10 @@ echo "$(tput setaf 4)Setting up...$(tput sgr0)"
|
||||
snapshot="${0:A:h}/snapshot.txt"
|
||||
current_branch=$(git branch --show-current)
|
||||
current_ref=$(git rev-parse HEAD)
|
||||
remote_url=$(git remote -v | grep "(push)" | awk '{print $2}')
|
||||
remote_url=$(git remote -v | grep "(push)" | grep "^origin " | head -1 | awk '{print $2}')
|
||||
if [[ -z "$remote_url" ]]; then
|
||||
remote_url=$(git remote -v | grep "(push)" | head -1 | awk '{print $2}')
|
||||
fi
|
||||
|
||||
__UTILS_PATH="${0:A:h}/utils.mock.zsh" \
|
||||
__UNLOAD_PATH="/dev/null" \
|
||||
@@ -94,6 +97,39 @@ assert_value "https://github.com/chenasraf/git-open/actions" $(git_open_pipeline
|
||||
describe "without args"
|
||||
assert_value "$(cat $snapshot)" "$(git_open)"
|
||||
|
||||
### Multi-remote tests
|
||||
echo ""
|
||||
echo "$(tput setaf 4)Setting up multi-remote tests...$(tput sgr0)"
|
||||
git remote add fake-upstream "https://github.com/fakeorg/git-open.git" 2>/dev/null
|
||||
|
||||
describe "git_get_remote prefers origin with multiple remotes"
|
||||
git_remote_name=""
|
||||
assert_value "$remote_url" $(git_get_remote)
|
||||
|
||||
describe "git_get_remote with --remote flag"
|
||||
git_remote_name="fake-upstream"
|
||||
assert_value "https://github.com/fakeorg/git-open.git" $(git_get_remote)
|
||||
|
||||
describe "git_open_project with --remote flag"
|
||||
git_remote_name="fake-upstream"
|
||||
assert_value "https://github.com/fakeorg/git-open" $(git_open_project)
|
||||
|
||||
describe "git_open_branch with --remote flag"
|
||||
git_remote_name="fake-upstream"
|
||||
assert_value "https://github.com/fakeorg/git-open/tree/$current_branch" $(git_open_branch)
|
||||
|
||||
describe "git_get_remote falls back to first when name not found"
|
||||
git_remote_name="nonexistent"
|
||||
result=$(git_get_remote)
|
||||
assert_value 0 $([[ -n "$result" ]] && echo 0 || echo 1)
|
||||
|
||||
# Reset remote name
|
||||
git_remote_name=""
|
||||
|
||||
echo ""
|
||||
echo "$(tput setaf 4)Cleaning up multi-remote tests...$(tput sgr0)"
|
||||
git remote remove fake-upstream 2>/dev/null
|
||||
|
||||
### Teardown
|
||||
echo ''
|
||||
echo "$(tput setaf 2)All tests passed!$(tput sgr0)"
|
||||
|
||||
Reference in New Issue
Block a user