# /* # * Copyright 2020 Intel Corporation, Inc # * # * Licensed under the Apache License, Version 2.0 (the "License"); # * you may not use this file except in compliance with the License. # * You may obtain a copy of the License at # * # * http://www.apache.org/licenses/LICENSE-2.0 # * # * Unless required by applicable law or agreed to in writing, software # * distributed under the License is distributed on an "AS IS" BASIS, # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # * See the License for the specific language governing permissions and # * limitations under the License. # */ # Additional functions to run negative tests set -o errexit set -o nounset set -o pipefail FUNCTIONS_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" my_directory=$(dirname $PWD) source /etc/environment source ${my_directory}/negative_tests/_test_variables_setup.sh source ${my_directory}/_common_test.sh source ${my_directory}/_functions.sh source ${my_directory}/_common.sh function call_api_negative { #Runs curl with passed flags and provides #additional error handling and debug information #Function outputs server response body #and performs validation of http_code local status local curl_response_file="$(mktemp -p /tmp)" local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}") local command=(curl "${curl_common_flags[@]}" "$@") echo "[INFO] Running '${command[@]}'" >&2 if ! status="$("${command[@]}")"; then echo "[ERROR] Internal curl error! '$status'" >&2 cat "${curl_response_file}" rm "${curl_response_file}" return 2 else echo "[INFO] Server replied with status: ${status}" >&2 cat "${curl_response_file}" rm "${curl_response_file}" return_status=$status fi } function delete_resource_negative { #Issues DELETE http call to provided endpoint #and further validates by following GET request call_api_negative -X DELETE "$1" #! call_api -X GET "$1" >/dev/null } function get_resource_negative { #! call_api_negative -X GET "$1" >/dev/null ! call_api_negative -X GET "$1" echo $return_status } # Create a test rpoject # EOF must start as first chracter in a line for cat to identify the end function create_project { project_name="test_project" project_description="test_project_description" userData1="user1" userData2="user2" print_msg "Registering project" payload="$(cat <