From d6c4a086f3d83d880d4fd8d18c21ab511d84a61f Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 4 Nov 2021 11:58:42 +0100 Subject: [PATCH] Add test for JSON API DirDetails handle type --- ...tails_handle_correct_64bit_integer_type.sh | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 tests/test_JSON_API_DirDetails_handle_correct_64bit_integer_type.sh diff --git a/tests/test_JSON_API_DirDetails_handle_correct_64bit_integer_type.sh b/tests/test_JSON_API_DirDetails_handle_correct_64bit_integer_type.sh new file mode 100755 index 000000000..95918256c --- /dev/null +++ b/tests/test_JSON_API_DirDetails_handle_correct_64bit_integer_type.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Copyright (C) 2021 Gioacchino Mazzurco +# Copyright (C) 2021 AsociaciĆ³n Civil Altermundi +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation, version 3. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see +# +# SPDX-FileCopyrightText: Retroshare Team +# SPDX-License-Identifier: AGPL-3.0-only + + +## Define default value for variable, take two arguments, $1 variable name, +## $2 default variable value, if the variable is not already define define it +## with default value. +function define_default_value() +{ + VAR_NAME="${1}" + DEFAULT_VALUE="${2}" + + [ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}" || true +} + +define_default_value API_BASE_URL "http://127.0.0.1:9092" +define_default_value API_TOKEN "0000:0000" + +function tLog() +{ + local mCategory="$1" ; shift + echo "$mCategory $(date) $@" >&2 +} + +mReply="$(curl -u "$API_TOKEN" "$API_BASE_URL/rsFiles/requestDirDetails")" + +[ "$(echo "$mReply" | jq '.retval')" == "true" ] || +{ + tLog E "/rsFiles/requestDirDetails failed: '$mReply'" + exit -1 +} + +[ "$(echo "$mReply" | jq '.details.handle')" != "0" ] || +{ + tLog E ".details.handle has wrong type int: '$mReply'" + exit -1 +} + +[ "$(echo "$mReply" | jq '.details.handle.xstr64')" == "\"0\"" ] && + [ "$(echo "$mReply" | jq '.details.handle.xint64')" == "0" ] && +{ + tLog I '.details.handle has correct type' + exit 0 +} + +tLog E "Unkown error in test $0: '$mReply'" +exit -2