Created
July 5, 2021 15:46
-
-
Save eloycoto/cf7ac3510dc0b8e1658e021503a6a883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
IFS=$'\t' | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
TESTCASES=$(cat <<-END | |
[ | |
{"path": "XX", "expected": "/XX"}, | |
{"path": "XXX", "expected": "/XXX"}, | |
{"path": "foo bar", "expected": "/foo%20bar"}, | |
{"path": "foo%20bar", "expected": "/foo%20bar"}, | |
{"path": "foo+bar", "expected": "/foo+bar"}, | |
{"path": "foo%2Bbar", "expected": "/foo+bar"}, | |
{"path": "foo%26bar", "expected": "/foo&bar"}, | |
{"path": "foo&bar", "expected": "/foo&bar"}, | |
{"path": "foo%24bar", "expected": "/foo\$bar"}, | |
{"path": "foo\$bar", "expected": "/foo\$bar"}, | |
{"path": "foo%23bar", "expected": "/foo%23bar"}, | |
{"path": "foo2019%2F05%2F07", "expected": "/foo2019/05/07"} | |
] | |
END | |
) | |
URL="http://172.19.0.3:8080/test/" | |
# URL="http://172.17.0.2:8080/" | |
HOST="one" | |
function expected_log() { | |
local result=$1 | |
local expected=$2 | |
local path=$3 | |
if [ "${result}" == "${expected}" ]; then | |
echo -e "${GREEN}✔️${NC}-> Path ${path} is correct ${result}" | |
return | |
fi | |
echo -e "${RED}❌${NC}-> Path '${path}' is not correct result='${result}' expected='${expected}'" | |
} | |
function test(){ | |
local path=$1 | |
local expected=$2 | |
local body=$(curl -s \ | |
-H "user_key: foo" -k \ | |
-H "Host: $HOST" "${URL}${path}?user_key=foo") | |
# echo $body | |
expected_log $(echo $body | jq -r '.path') $expected $path | |
} | |
echo $TESTCASES | jq -r '.[] | [.path, .expected] | @tsv' | while read -r key val; do | |
# echo "'${key}'" | |
# echo "'${val}'" | |
test $key $val | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment