test: add more testing

This commit is contained in:
Luke McCrone
2026-01-26 16:13:38 -03:00
parent a1d8161aaa
commit a3e3aa330a
2 changed files with 42 additions and 0 deletions

View File

@@ -126,9 +126,39 @@ get_curl_method() {
}
get_curl_route() {
local url="$1"
local path
# Only accept http/https URLs with a path
if [[ ! "$url" =~ ^https?://[^/]+(/.*)?$ ]]; then
echo "UNKNOWN"
return 0
fi
# Strip protocol + host + port
path="$(echo "$url" | sed -E 's|https?://[^/]+||')"
# Normalize: remove leading/trailing slashes
path="${path#/}"
path="${path%/}"
# Split path on '/'
IFS='/' read -r -a parts <<< "$path"
if [[ -z "$path" ]]; then
echo "MAIN"
elif [[ "${#parts[@]}" -eq 1 ]]; then
echo "BUCKET"
else
echo "FILE"
fi
return 0
}
get_query() {
}
parse_curl_rest_command() {
if ! check_param_count "command string" 1 $#; then
return 1

View File

@@ -32,5 +32,17 @@ source ./tests/report.sh
}
@test "reporting - parse curl route" {
tests=("http://localhost:7070/bucket_name" "http://localhost:7070/bucket_name/file_name" "http://localhost:7070/" "")
expected_results=("BUCKET" "FILE" "MAIN" "UNKNOWN")
for ((i=0; i<${#tests[@]}; i++)); do
echo "test: ${tests[$i]}, expected result: ${expected_results[$i]}"
run get_curl_route "${tests[$i]}"
assert_output "${expected_results[$i]}"
done
}
@test "reporting - get query" {
tests=("https://localhost:7070/?query1=" "https://localhost/bucket?another=" "https://1.2.3.4/" "http://localhost/bucket/file?third")
expected_results=("query1" "another" "" "third")
}