Skip to content

Commit

Permalink
Fix unittest for pathtype
Browse files Browse the repository at this point in the history
  • Loading branch information
hailihu committed Jan 27, 2025
1 parent e21fbcf commit dc846eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
35 changes: 19 additions & 16 deletions ada/ada
Original file line number Diff line number Diff line change
Expand Up @@ -796,23 +796,26 @@ pathtype () {
# <empty> = something went wrong... no permission?
local result
encoded_path=$(urlencode "$1")
result=$(
$debug && set -x
curl "${curl_authorization[@]}" \
-H 'accept: application/json' \
--silent \
-X GET "$api/namespace/$encoded_path"
)
valid=$(echo "$result" | jq 'has("fileType")')
if [[ $valid == 'true' ]] ; then
echo "$result" | jq -r .fileType
command='$debug && set -x
curl "${curl_authorization[@]}" \
-H "accept: application/json" \
--silent \
-X GET "$api/namespace/$encoded_path"'
if $dry_run ; then
echo "$command"
else
# Something went wrong. The result should contain an error message in JSON format.
{
echo "Error while getting information about '$path':"
echo "$result" | jq .
} 1>&2
exit 1
result=$(eval "$command")
valid=$(echo "$result" | jq 'has("fileType")')
if [[ $valid == 'true' ]] ; then
echo "$result" | jq -r .fileType
else
# Something went wrong. The result should contain an error message in JSON format.
{
echo "Error while getting information about '$path':"
echo "$result" | jq .
} 1>&2
exit 1
fi
fi
}

Expand Down
9 changes: 5 additions & 4 deletions tests/unit_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ test_urlencode() {

test_pathtype() {
result=`pathtype "/test/a/b/c"`
expected='curl "${curl_authorization[@]}" \
"${curl_options_no_errors[@]}" \
-X GET "$api/namespace/$path" \
| jq -r .fileType'
expected='$debug && set -x
curl "${curl_authorization[@]}" \
-H "accept: application/json" \
--silent \
-X GET "$api/namespace/$encoded_path"'
assertEquals \
"the result of pathtype() was wrong" \
"${expected}" "${result}"
Expand Down

0 comments on commit dc846eb

Please sign in to comment.