|
|
|
@@ -1,298 +0,0 @@
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Git URL Parsing Tests for kugetsu
|
|
|
|
|
|
|
|
# Tests all functions that parse or construct git URLs and issue refs
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Run with: bash skills/kugetsu/tests/test-git-url-parsing.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
|
|
|
source "$SCRIPT_DIR/../scripts/kugetsu-config.sh"
|
|
|
|
|
|
|
|
source "$SCRIPT_DIR/../scripts/kugetsu-worktree.sh"
|
|
|
|
|
|
|
|
source "$SCRIPT_DIR/../scripts/kugetsu-session.sh"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PASS=0
|
|
|
|
|
|
|
|
FAIL=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pass() {
|
|
|
|
|
|
|
|
echo "PASS: $1"
|
|
|
|
|
|
|
|
PASS=$((PASS + 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
|
|
|
|
echo "FAIL: $1"
|
|
|
|
|
|
|
|
echo " Expected: $2"
|
|
|
|
|
|
|
|
echo " Got: $3"
|
|
|
|
|
|
|
|
FAIL=$((FAIL + 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "=== Git URL Parsing Test Suite ==="
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with standard GitHub issue ref
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with github.com ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "github.com/shoko/kugetsu#14")
|
|
|
|
|
|
|
|
expected="https://github.com/shoko/kugetsu.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url standard github issue ref"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url standard github issue ref" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with custom instance
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with git.fbrns.co ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "git.fbrns.co/shoko/kugetsu#158")
|
|
|
|
|
|
|
|
expected="https://git.fbrns.co/shoko/kugetsu.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url custom instance issue ref (ISSUE #181)"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url custom instance issue ref (ISSUE #181)" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with gitlab.com (if configured)
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with gitlab.com ---"
|
|
|
|
|
|
|
|
if [ -n "${GIT_SERVERS[gitlab.com]:-}" ]; then
|
|
|
|
|
|
|
|
result=$(get_repo_url "gitlab.com/someuser/somerepo#42")
|
|
|
|
|
|
|
|
expected="https://gitlab.com/someuser/somerepo.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url gitlab.com issue ref"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url gitlab.com issue ref" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "SKIP: get_repo_url gitlab.com (not configured in GIT_SERVERS)"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with bitbucket.org (if configured)
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with bitbucket.org ---"
|
|
|
|
|
|
|
|
if [ -n "${GIT_SERVERS[bitbucket.org]:-}" ]; then
|
|
|
|
|
|
|
|
result=$(get_repo_url "bitbucket.org/myteam/myproject#7")
|
|
|
|
|
|
|
|
expected="https://bitbucket.org/myteam/myproject.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url bitbucket.org issue ref"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url bitbucket.org issue ref" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "SKIP: get_repo_url bitbucket.org (not configured in GIT_SERVERS)"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with large issue number
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with large issue number ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "github.com/shoko/kugetsu#999999")
|
|
|
|
|
|
|
|
expected="https://github.com/shoko/kugetsu.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url with large issue number"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url with large issue number" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_worktree_name standard
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_worktree_name standard ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_worktree_name "github.com/shoko/kugetsu#14")
|
|
|
|
|
|
|
|
expected="github.com-shoko-kugetsu-14"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_worktree_name standard"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_worktree_name standard" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_worktree_name with custom instance
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_worktree_name custom instance ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_worktree_name "git.fbrns.co/shoko/kugetsu#158")
|
|
|
|
|
|
|
|
expected="git.fbrns.co-shoko-kugetsu-158"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_worktree_name custom instance"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_worktree_name custom instance" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_branch_name with number
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_branch_name with number ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#14")
|
|
|
|
|
|
|
|
expected="fix/issue-14"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_branch_name with number"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_branch_name with number" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_branch_name with discuss suffix
|
|
|
|
|
|
|
|
# Note: #-discuss falls through to fix/issue-temp because #[^-]+$ doesn't match #-<text-with-hyphens>
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_branch_name with discuss suffix ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#-discuss")
|
|
|
|
|
|
|
|
expected="fix/issue-temp"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_branch_name with discuss suffix"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_branch_name with discuss suffix" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_branch_name with identifier that has no hyphens
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_branch_name with pure identifier ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#someid")
|
|
|
|
|
|
|
|
expected="fix/someid"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_branch_name with pure identifier"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_branch_name with pure identifier" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_branch_name without number
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_branch_name without number ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_branch_name "github.com/shoko/kugetsu#abc")
|
|
|
|
|
|
|
|
expected="fix/abc"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_branch_name without number"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_branch_name without number" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with short form
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message short form ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "github.com/shoko/kugetsu#14")
|
|
|
|
|
|
|
|
expected="github.com/shoko/kugetsu#14"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message short form"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message short form" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with https URL
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message with https URL ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "https://github.com/shoko/kugetsu/issues/14")
|
|
|
|
|
|
|
|
expected="github.com/shoko/kugetsu#14"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message with https URL"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message with https URL" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with custom instance
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message custom instance ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "https://git.fbrns.co/shoko/kugetsu/issues/158")
|
|
|
|
|
|
|
|
expected="git.fbrns.co/shoko/kugetsu#158"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message custom instance"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message custom instance" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with empty message
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message empty message ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "")
|
|
|
|
|
|
|
|
expected=""
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message empty message"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message empty message" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with no issue ref
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message no issue ref ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "Just a regular message without any issue reference")
|
|
|
|
|
|
|
|
expected=""
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message no issue ref"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message no issue ref" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: extract_issue_ref_from_message with gitlab URL
|
|
|
|
|
|
|
|
echo "--- Test: extract_issue_ref_from_message gitlab URL ---"
|
|
|
|
|
|
|
|
result=$(extract_issue_ref_from_message "https://gitlab.com/someuser/somerepo/issues/42")
|
|
|
|
|
|
|
|
expected="gitlab.com/someuser/somerepo#42"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "extract_issue_ref_from_message gitlab URL"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "extract_issue_ref_from_message gitlab URL" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: validate_issue_ref valid format
|
|
|
|
|
|
|
|
echo "--- Test: validate_issue_ref valid format ---"
|
|
|
|
|
|
|
|
if validate_issue_ref "github.com/shoko/kugetsu#14" 2>/dev/null; then
|
|
|
|
|
|
|
|
pass "validate_issue_ref valid format"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "validate_issue_ref valid format" "exit 0" "exit non-zero"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: validate_issue_ref invalid format (missing parts)
|
|
|
|
|
|
|
|
echo "--- Test: validate_issue_ref invalid format ---"
|
|
|
|
|
|
|
|
if ! validate_issue_ref "invalid-ref" 2>/dev/null; then
|
|
|
|
|
|
|
|
pass "validate_issue_ref invalid format"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "validate_issue_ref invalid format" "exit non-zero" "exit 0"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: issue_ref_to_filename
|
|
|
|
|
|
|
|
echo "--- Test: issue_ref_to_filename ---"
|
|
|
|
|
|
|
|
result=$(issue_ref_to_filename "github.com/shoko/kugetsu#14")
|
|
|
|
|
|
|
|
expected="github.com-shoko-kugetsu-14.json"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "issue_ref_to_filename"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "issue_ref_to_filename" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: filename_to_issue_ref
|
|
|
|
|
|
|
|
echo "--- Test: filename_to_issue_ref ---"
|
|
|
|
|
|
|
|
result=$(filename_to_issue_ref "github.com-shoko-kugetsu-14.json")
|
|
|
|
|
|
|
|
expected="github.com/shoko/kugetsu#14"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "filename_to_issue_ref"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "filename_to_issue_ref" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with org having hyphen
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with hyphenated org ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "github.com/my-org/my-repo#1")
|
|
|
|
|
|
|
|
expected="https://github.com/my-org/my-repo.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url with hyphenated org"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url with hyphenated org" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with repo having dots
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with dotted repo ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "github.com/shoko/kugetsu.utils#5")
|
|
|
|
|
|
|
|
expected="https://github.com/shoko/kugetsu.utils.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url with dotted repo"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url with dotted repo" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with underscore in username
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with underscore in user ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "github.com/my_user/my_repo#10")
|
|
|
|
|
|
|
|
expected="https://github.com/my_user/my_repo.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url with underscore in user"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url with underscore in user" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test: get_repo_url with instance not in GIT_SERVERS (fallback)
|
|
|
|
|
|
|
|
echo "--- Test: get_repo_url with unknown instance ---"
|
|
|
|
|
|
|
|
result=$(get_repo_url "unknown.example.com/owner/repo#1")
|
|
|
|
|
|
|
|
expected="https://unknown.example.com/owner/repo.git"
|
|
|
|
|
|
|
|
if [ "$result" = "$expected" ]; then
|
|
|
|
|
|
|
|
pass "get_repo_url with unknown instance"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "get_repo_url with unknown instance" "$expected" "$result"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "=== Test Results ==="
|
|
|
|
|
|
|
|
echo "Passed: $PASS"
|
|
|
|
|
|
|
|
echo "Failed: $FAIL"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ $FAIL -eq 0 ]; then
|
|
|
|
|
|
|
|
echo "All tests passed!"
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Some tests failed!"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|