From a3e3aa330aa555c19c9dafc07dc2ec0fdd51fd1b Mon Sep 17 00:00:00 2001 From: Luke McCrone Date: Mon, 26 Jan 2026 16:13:38 -0300 Subject: [PATCH] test: add more testing --- tests/report.sh | 30 ++++++++++++++++++++++++++++++ tests/test_report.sh | 12 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/report.sh b/tests/report.sh index 058c9cd..8139a68 100644 --- a/tests/report.sh +++ b/tests/report.sh @@ -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 diff --git a/tests/test_report.sh b/tests/test_report.sh index 3a9c1f9..b19fc5d 100755 --- a/tests/test_report.sh +++ b/tests/test_report.sh @@ -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") } \ No newline at end of file