Skip to content

Commit cfd7691

Browse files
authored
Merge pull request #25 from subeshb1/fix/dash_number_key_failure
Add quote to dynamically accessed key names
2 parents 03d91ff + bd31aa1 commit cfd7691

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name: CI
44

5-
on: [push, pull_request]
5+
on: [push]
66

77
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
88
jobs:

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.3.2

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Changelog
22

3-
## v0.3.1
3+
## v0.3.2
4+
- Fix script breaking on test cases starting with numbers Eg: `01_testcase, 02_testcase` and containing hyphen `-` Eg: `test-case`
45

6+
## v0.3.1
57
- Fixed null body being sent when no body content was provided.
68
- Fixed typo in external script test message.
79

api-test.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ function usage() {
138138

139139
# api methods
140140
call_api() {
141-
ROUTE=$(jq -r ".testCases.$1.path" $FILE)
142-
BODY="$(jq -r ".testCases.$1 | select(.body != null) | .body" $FILE)"
143-
QUERY_PARAMS=$(cat $FILE | jq -r ".testCases.$1 | select(.query != null) | .query | to_entries | map(\"\(.key)=\(.value|tostring)\") | join(\"&\") | \"?\" + . ")
144-
REQUEST_HEADER=$(cat $FILE | jq -r ".testCases.$1 | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
145-
METHOD="$(jq -r ".testCases.$1.method //\"GET\" | ascii_upcase" $FILE)"
141+
ROUTE=$(jq -r ".testCases.\"$1\".path" $FILE)
142+
BODY="$(jq -r ".testCases.\"$1\" | select(.body != null) | .body" $FILE)"
143+
QUERY_PARAMS=$(cat $FILE | jq -r ".testCases.\"$1\" | select(.query != null) | .query | to_entries | map(\"\(.key)=\(.value|tostring)\") | join(\"&\") | \"?\" + . ")
144+
REQUEST_HEADER=$(cat $FILE | jq -r ".testCases.\"$1\" | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
145+
METHOD="$(jq -r ".testCases.\"$1\".method //\"GET\" | ascii_upcase" $FILE)"
146146
# curl -ivs --request $METHOD "$URL$ROUTE$QUERY_PARAMS" \
147147
# --data "$BODY" \
148148
# "$COMMON_HEADER" \
@@ -211,8 +211,8 @@ api_factory() {
211211
for TEST_CASE in $@; do
212212
API_ERROR=0
213213
echo "${BOLD}Running Case:${RESET} $TEST_CASE"
214-
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.$TEST_CASE.description" $FILE)"
215-
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.$TEST_CASE.path" $FILE)"
214+
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".description" $FILE)"
215+
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.\"$TEST_CASE\".path" $FILE)"
216216
call_api $TEST_CASE
217217
display_results
218218
echo ""
@@ -227,9 +227,9 @@ test_factory() {
227227
for TEST_CASE in $@; do
228228
API_ERROR=0
229229
echo "${BOLD}Testing Case:${RESET} $TEST_CASE"
230-
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.$TEST_CASE.description" $FILE)"
231-
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.$TEST_CASE.method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.$TEST_CASE.path" $FILE)"
232-
if [[ -z $(jq -r ".testCases.$TEST_CASE.expect? | select(. !=null)" $FILE) ]]; then
230+
echo_v "${BOLD}Description: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".description" $FILE)"
231+
echo_v "${BOLD}Action: ${RESET}$(jq -r ".testCases.\"$TEST_CASE\".method //\"GET\" | ascii_upcase" $FILE) $(jq -r ".testCases.\"$TEST_CASE\".path" $FILE)"
232+
if [[ -z $(jq -r ".testCases.\"$TEST_CASE\".expect? | select(. !=null)" $FILE) ]]; then
233233
tput cuf 2
234234
echo "No test cases found"
235235
echo ""
@@ -245,7 +245,7 @@ test_factory() {
245245
continue
246246
fi
247247

248-
local TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.header? | select(. !=null and . != {})" $FILE)
248+
local TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.header? | select(. !=null and . != {})" $FILE)
249249
if [[ ! -z $TEST_SCENARIO ]]; then
250250
tput cuf 2
251251
echo "${UNDERLINE}Checking condition for header${RESET}"
@@ -254,7 +254,7 @@ test_factory() {
254254
echo ""
255255
fi
256256

257-
TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.body? | select(. !=null and . != {})" $FILE)
257+
TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.body? | select(. !=null and . != {})" $FILE)
258258
if [[ ! -z $TEST_SCENARIO ]]; then
259259
tput cuf 2
260260
echo "${UNDERLINE}Checking condition for body${RESET}"
@@ -263,7 +263,7 @@ test_factory() {
263263
echo ""
264264
fi
265265

266-
TEST_SCENARIO=$(jq -r ".testCases.$TEST_CASE.expect.external? | select(. !=null and . != \"\")" $FILE)
266+
TEST_SCENARIO=$(jq -r ".testCases.\"$TEST_CASE\".expect.external? | select(. !=null and . != \"\")" $FILE)
267267
if [[ ! -z $TEST_SCENARIO ]]; then
268268
tput cuf 2
269269
echo "${UNDERLINE}Checking condition from external program${RESET}"
@@ -299,7 +299,7 @@ test_factory() {
299299

300300
test_runner() {
301301
for test in ""contains eq path_eq path_contains hasKey[]""; do
302-
local TEST_SCENARIO=$(jq -c -r ".testCases.$1.expect.$2.$test? | select(. !=null)" $FILE)
302+
local TEST_SCENARIO=$(jq -c -r ".testCases.\"$1\".expect.$2.$test? | select(. !=null)" $FILE)
303303
if [[ -z $TEST_SCENARIO ]]; then
304304
continue
305305
fi

test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hayd/ubuntu-deno:1.0.2
1+
FROM hayd/ubuntu-deno:1.3.1
22

33

44
WORKDIR /app

test/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ const getBook = (ctx: RouterContext<any>) => {
4141

4242
const postBook = async (ctx: RouterContext<RouteParams>) => {
4343
const { request, response } = ctx;
44+
response.type = 'application/json'
4445
if (request.hasBody) {
4546
const result: any = await request.body({
4647
contentTypes: {
4748
text: ["application/javascript"],
4849
},
49-
});
50-
const body: any = JSON.parse(result.value)
50+
})
51+
const body: {id:string} = await result.value
5152
const book: IBook | undefined = searchBookById(body.id)
52-
if (!book) {
53+
if (!book) {
5354
response.status = 200
5455
response.body = body
5556
} else {

test/test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
},
2828
"url": "api-test:3000",
2929
"header": {
30-
"Content-Type": "application/javascript"
30+
"Content-Type": "application/json"
3131
}
3232
}

0 commit comments

Comments
 (0)