Skip to content

Commit 89a0b10

Browse files
committed
test: add/fix remote tests
1 parent 4a39ec3 commit 89a0b10

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

tests/snapshot.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Commands:
1616

1717
Flags:
1818
-s, --silent Silent mode (no output)
19+
-r, --remote <name> Use a specific remote (default: origin)

tests/test.zsh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ echo "$(tput setaf 4)Setting up...$(tput sgr0)"
1010
snapshot="${0:A:h}/snapshot.txt"
1111
current_branch=$(git branch --show-current)
1212
current_ref=$(git rev-parse HEAD)
13-
remote_url=$(git remote -v | grep "(push)" | awk '{print $2}')
13+
remote_url=$(git remote -v | grep "(push)" | grep "^origin " | head -1 | awk '{print $2}')
14+
if [[ -z "$remote_url" ]]; then
15+
remote_url=$(git remote -v | grep "(push)" | head -1 | awk '{print $2}')
16+
fi
1417

1518
__UTILS_PATH="${0:A:h}/utils.mock.zsh" \
1619
__UNLOAD_PATH="/dev/null" \
@@ -94,6 +97,39 @@ assert_value "https://github.com/chenasraf/git-open/actions" $(git_open_pipeline
9497
describe "without args"
9598
assert_value "$(cat $snapshot)" "$(git_open)"
9699

100+
### Multi-remote tests
101+
echo ""
102+
echo "$(tput setaf 4)Setting up multi-remote tests...$(tput sgr0)"
103+
git remote add fake-upstream "https://github.com/fakeorg/git-open.git" 2>/dev/null
104+
105+
describe "git_get_remote prefers origin with multiple remotes"
106+
git_remote_name=""
107+
assert_value "$remote_url" $(git_get_remote)
108+
109+
describe "git_get_remote with --remote flag"
110+
git_remote_name="fake-upstream"
111+
assert_value "https://github.com/fakeorg/git-open.git" $(git_get_remote)
112+
113+
describe "git_open_project with --remote flag"
114+
git_remote_name="fake-upstream"
115+
assert_value "https://github.com/fakeorg/git-open" $(git_open_project)
116+
117+
describe "git_open_branch with --remote flag"
118+
git_remote_name="fake-upstream"
119+
assert_value "https://github.com/fakeorg/git-open/tree/$current_branch" $(git_open_branch)
120+
121+
describe "git_get_remote falls back to first when name not found"
122+
git_remote_name="nonexistent"
123+
result=$(git_get_remote)
124+
assert_value 0 $([[ -n "$result" ]] && echo 0 || echo 1)
125+
126+
# Reset remote name
127+
git_remote_name=""
128+
129+
echo ""
130+
echo "$(tput setaf 4)Cleaning up multi-remote tests...$(tput sgr0)"
131+
git remote remove fake-upstream 2>/dev/null
132+
97133
### Teardown
98134
echo ''
99135
echo "$(tput setaf 2)All tests passed!$(tput sgr0)"

0 commit comments

Comments
 (0)