Skip to content

Commit 0920b76

Browse files
committed
Add path_contains support and fix multi keys bug
1 parent 54892cc commit 0920b76

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

api-test.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ test_factory() {
206206
}
207207

208208
test_runner() {
209-
for test in ""contains eq path_eq hasKey[]""; do
209+
for test in ""contains eq path_eq path_contains hasKey[]""; do
210210
local TEST_SCENARIO=$(jq -r ".testCases.$1.expect.$2.$test? | select(. !=null)" $FILE)
211211
if [[ -z $TEST_SCENARIO ]]; then
212212
continue
@@ -220,7 +220,10 @@ test_runner() {
220220
check_eq "$TEST_SCENARIO" "$3"
221221
elif [[ $test == "path_eq" ]]; then
222222
echo "Checking path equality comparision${RESET}"
223-
path_eq "$TEST_SCENARIO" "$3"
223+
path_checker "$TEST_SCENARIO" "$3"
224+
elif [[ $test == "path_contains" ]]; then
225+
echo "Checking path equality comparision${RESET}"
226+
path_checker "$TEST_SCENARIO" "$3" 1
224227
else
225228
echo "Checking has key comparision${RESET}"
226229
has_key "$TEST_SCENARIO" "$3"
@@ -292,15 +295,15 @@ check_eq() {
292295
fi
293296
}
294297

295-
path_eq() {
298+
path_checker() {
296299
local keys=$(jq -r --argjson a "$1" -n '$a | keys[]')
297300
if [[ -z "$keys" ]]; then
298301
return
299302
fi
300-
for key in "$keys"; do
303+
for key in $keys; do
301304
tput cuf 6
302305
local value=$(jq -c -r --argjson a "$1" -n "\$a | .\"$key\"")
303-
echo "When path is '$key' and value is $value"
306+
echo "When path is '$key'"
304307
local compare_value=$(jq -r --argjson a "$2" -n "\$a | try .$key catch \"OBJECT_FETCH_ERROR_JQ_API_TEST\"" 2>/dev/null)
305308
if [[ -z "$compare_value" ]]; then
306309
tput cuf 8
@@ -310,7 +313,11 @@ path_eq() {
310313
return
311314
fi
312315
tput cuf 2
313-
check_eq "$value" "$compare_value"
316+
if [[ $3 == 0 ]]; then
317+
check_eq "$value" "$compare_value"
318+
else
319+
contains "$value" "$compare_value"
320+
fi
314321
done
315322
}
316323

0 commit comments

Comments
 (0)